按名称和用户杀死进程
我想弄清楚是否有一种方法可以按名称和用户杀死所有进程。例如,我想杀死用户 myuser 运行的所有 Java 实例。
截至目前,我这样做:
$ pgrep -u myuser java
2185
3281
3413
3504
22534
26174
27554
它给出了 mysuer 运行的 java 的 pid 列表。然后我单独杀死每个 pid。有更好的方法吗?
提前致谢!
I am trying to figure out if there is a way to kill all processes by name and user. E.g. I want to kill all the Java instances run by user myuser.
As of the moment I do:
$ pgrep -u myuser java
2185
3281
3413
3504
22534
26174
27554
which gives a list of the pid of java run by mysuer. Then I kill each pid individually. Is there a better way to do this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用
killall(1)
:请注意,您可能需要通过
sudo
执行此操作,您可能需要-9
来终止吞下SIGTERM
的进程:Use
killall(1)
:Note that you may need to do this via
sudo
, and you may need-9
to kill processes that swallowSIGTERM
:以下命令可以完成这项工作
,注意 process_name 也可以是正则表达式。
following command can do the job
note that process_name can be a regular expression also.
你很接近:
You're close:
我知道这已经很旧了,但这里有一个 bash 脚本可以轻松完成此操作...:
这是我写的关于此主题的博客文章,用于杀死一组进程: https://soroo.sh/linux/kill-processess-by-name
I know this is old but here it is an bash script to doing this easily...:
Here it's a blog post I wrote about this topic for killing a group of processes : https://soroo.sh/linux/kill-processess-by-name
您可以通过使用来完成此操作
,但有时这会导致进程失效。
最好的方法可能是这样的:-
注意:- 如果您正在终止由您登录的用户启动的进程,这也会终止您当前在服务器上登录的会话。
谢谢。
You can do this by using
But sometimes this will result in a defunct process.
The best way could be like this :-
NOTE :- this will also kill your current logged in session on the server if you are killing processes started by the user which you are logged on.
Thanks.