不知Linux原生是否有自带这类命令……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
kill_pid_recursively()
{
local pid=$1
local parent_pid=$2
if [ ! -z ${pid} ]; then
for child_pid in `pgrep -P ${pid}`; do
kill_pid_recursively ${child_pid} ${pid}
done
echo "kill PID: ${pid}, its PPID is ${parent_pid}"
kill -9 ${pid}
fi
}

kill_pid_recursively ${SOME_PID} 'nothing'