pstree -ap <pid>
[pkill will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout.]
[-P, --parent ppid,... Only match processes whose parent process ID is listed.]
-- from man pkill
pkill -9 -P <pid> (It only kills its currently running subprocesses, doesn't kill the process itself, so the left commands will start. Carefully us it!!!)
zzh@ZZHPC:~/aaa$ cat test_bash_shebang.sh #!/bin/bash echo 'sleep 500s' sleep 500 echo 'sleep 300s' sleep 300 zzh@ZZHPC:~/aaa$ ./test_bash_shebang.sh sleep 500s
zzh@ZZHPC:~$ psvgrep test_bash_shebang.sh zzh 7356 5189 0 11:19 pts/0 00:00:00 /bin/bash ./test_bash_shebang.sh zzh@ZZHPC:~$ pstree -ap 7356 test_bash_sheba,7356 ./test_bash_shebang.sh └─sleep,7357 500 zzh@ZZHPC:~$ pkill -9 -P 7356
'sleep 500' was killed, 'sleep 300' started:
zzh@ZZHPC:~/aaa$ ./test_bash_shebang.sh sleep 500s ./test_bash_shebang.sh: line 4: 7357 Killed sleep 500 sleep 300s
可以利用pstree列出所有子进程,然后用kill来杀。