向流程组的所有成员发送信号的最佳方法是什么? [英] What's the best way to send a signal to all members of a process group?

查看:64
本文介绍了向流程组的所有成员发送信号的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想杀死整个进程树.使用任何常用脚本语言执行此操作的最佳方法是什么?我正在寻找一个简单的解决方案.

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.

推荐答案

您没有说要杀死的树是否是单个进程组. (如果树是从服务器启动或shell命令行派生的结果,通常是这种情况.)您可以使用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 "

如果这是您要杀死的进程组,只需使用kill(1)命令,但不要给它一个进程号,而应给它一个组号的否定.例如,要杀死5112组中的每个进程,请使用kill -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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆