如何在linux中杀死多个进程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12951348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:37:55  来源:igfitidea点击:

How to kill more than one process in linux?

linux

提问by Mallikarjuna Reddy

I want to kill some of Apache server process in Linux.

我想在 Linux 中杀死一些 Apache 服务器进程。

Please help me in this.

请帮助我。

采纳答案by Harry Joy

if you have pid of the processes that want to kill then use killcommand.

如果您有要杀死的进程的 pid,则使用kill命令。

kill pid1 [pid2 pid3 ...]

And if this doesn't kill the processes you can add -9flag to killcommand to forcefully kill the processes like

如果这不会杀死进程,您可以-9kill命令添加标志以强行杀死进程,例如

kill -9 pid1 [pid2 pid3 ...]

To get the pid of the process you can use pscommand as

要获取进程的 pid,您可以使用ps命令作为

ps ax | grep apache

first column of output is the pid of the process.

输出的第一列是进程的pid。

回答by Olaf Dietsche

Try the following:

请尝试以下操作:

killall apache2

if you want to kill all apache processes.

如果你想杀死所有的 apache 进程。

ps aux | grep apache2

will show the apache servers with their PID. Then you can kill selectively:

将显示带有 PID 的 apache 服务器。然后你可以有选择地杀死:

kill -9 pid1 pid5

回答by Brian Agnew

Note the Linux command killall. You can kill processes by name and thus do something a little more coarse-grained than using the pid. You can use names or regular expressions (with the -roption) to specifiy your victims.

请注意 Linux 命令killall。您可以按名称终止进程,从而执行比使用 pid 更粗粒度的操作。您可以使用名称或正则表达式(带有-r选项)来指定您的受害者。

Use a normal SIGTERM(default) to begin with. This will let the processes catch the signal, and if they're well-behaved they'll clear up/close resources properly and then exit. Only if the processes don't respond should you use the SIGKILL(-9) signal.

使用普通SIGTERM(默认)开始。这将使进程捕获信号,如果它们表现良好,它们将正确清除/关闭资源,然后退出。只有当进程没有响应时才应该使用SIGKILL(-9) 信号。