-
-
Save marek-saji/9374783 to your computer and use it in GitHub Desktop.
Kill all the children
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo outer | |
./2.sh | |
echo /outer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
#trap 'ps -opid= --sort=start_time --ppid=$$ | head -n-2 | xargs kill' INT TERM QUIT EXIT | |
kill_children () | |
{ | |
PPID=$1 | |
for CHILD_PID in $( ps -opid= --sort=start_time --ppid=$PPID | head -n-1 ) | |
do | |
kill_children ${CHILD_PID} | |
kill ${CHILD_PID} | |
done | |
} | |
trap 'kill_children $$' INT TERM QUIT EXIT | |
echo inner | |
sh -c 'sleep 0.6 ; echo -n ~~~' & | |
sh -c 'sleep 0.5 ; echo -n HELLO' & | |
echo /inner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment