diff --git a/scripts/jw-build-functions.sh b/scripts/jw-build-functions.sh index ce658c8a..ae3bd3d4 100644 --- a/scripts/jw-build-functions.sh +++ b/scripts/jw-build-functions.sh @@ -76,3 +76,47 @@ ytools_source_configs() 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 +} +