杀死所有的子进程的最佳方法 [英] Best way to kill all child processes
问题描述
我要杀死整个进程树。什么是做到这一点使用任何常见的脚本语言的最佳方式?我要寻找一个简单的解决方案。
I want to kill a whole process tree. What is the best way to do this using any common scripting languages? I am looking for a simple solution.
推荐答案
你不说,如果你想杀死树是一个进程组。 (这是常有的事,如果树是从服务器启动或外壳命令行分叉的结果。)您可以使用GNU ps的发现过程组如下:
You don't say if the tree you want to kill is a single process group. (This is often the case if the tree is the result of forking from a server start or a shell command line.) You can discover process groups using GNU ps as follows:
ps x -o "%p %r %y %x %c "
如果这是你要杀死一个进程组,只需使用杀(1)
命令,但不是给它一个进程号,给它的否定的组号码。例如在5112组杀掉每一道工序,使用杀-TERM -5112
。
If it is a process group you want to kill, just use the kill(1)
command but instead of giving it a process number, give it the negation of the group number. For example to kill every process in group 5112, use kill -TERM -5112
.
这篇关于杀死所有的子进程的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!