mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 12:03:31 +01:00
jw-build-functions.sh: Add new functions
Add new functions: - ytools_cat() - ytools_waitpid() - ytools_terminate()
This commit is contained in:
parent
51d01b90bb
commit
3a4fb745b2
1 changed files with 44 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue