Skip to content

Instantly share code, notes, and snippets.

@marek-saji
Last active October 23, 2016 19:08
Show Gist options
  • Save marek-saji/9374783 to your computer and use it in GitHub Desktop.
Save marek-saji/9374783 to your computer and use it in GitHub Desktop.
Kill all the children
#!/bin/sh
echo outer
./2.sh
echo /outer
#!/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