jw-build-functions.sh: Add new functions

Add new functions:

  - ytools_cat()
  - ytools_waitpid()
  - ytools_terminate()
This commit is contained in:
Jan Lindemann 2010-11-13 15:16:33 +00:00 committed by Jan Lindemann
commit 3a4fb745b2

View file

@ -76,3 +76,47 @@ ytools_source_configs()
done done
} }
ytools_cat()
{
cat | sed 's/^[ ]*|//'
}
ytools_waitpid()
{
local pid=$1
local t=5
[ "$2" ] && t=$2
while ((t > 0)); do
[ -f /proc/$pid/status ] || {
wait $pid
return 0
}
sleep 1
((t -= 1))
done
return 1
}
ytools_terminate()
{
local pid
for pid in $@; do
[ -f /proc/$pid/status ] && {
echo terminating process $pid
kill $pid
ytools_waitpid $pid || {
echo "failed to normally terminate process $pid, killing it" >&2
kill -9 $pid
ytools_waitpid $pid || {
echo "failed to kill process $pid" >&2
return 1
}
}
}
done
return 0
}