#!/bin/bash

# http://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes/15139734#15139734
killtree() {
    local _pid=`cat /tmp/blinkypid`
    local _sig="SIGKILL"
    kill -stop ${_pid} # needed to stop quickly forking parent from producing children between child killing and parent killing
    for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
        killtree ${_child} ${_sig}
    done
    kill -${_sig} ${_pid}
}

if [ $# -eq 0 -o $# -gt 2 ]; then
    echo "Usage: $(basename $0) <pid> [signal]"
    exit 1
fi

killtree()
#!/bin/bash

# http://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes/15139734#15139734
killtree() {
    local _pid=`cat /tmp/blinkypid`
    local _sig="SIGKILL"
    kill -stop ${_pid} # needed to stop quickly forking parent from producing children between child killing and parent killing
    for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
        killtree ${_child} ${_sig}
    done
    kill -${_sig} ${_pid}
}

if [ $# -eq 0 -o $# -gt 2 ]; then
    echo "Usage: $(basename $0) <pid> [signal]"
    exit 1
fi

if [ -f /tmp/blinkypid ]; then
    killtree()
fi
Check if PID file exists in application stop.
Check if PID file exists in application stop.
