从命令行杀死所有进程

发布于 2024-12-22 06:24:00 字数 1293 浏览 0 评论 0原文

我想从命令行杀死所有 Firefox 进程。

例如:

MacPro:huangr$ ps -x | grep 'firefox'
 4147 ttys000    0:00.00 (firefox-bin)
 4177 ttys000    0:00.00 (firefox-bin)
 4234 ttys000    0:00.00 (firefox-bin)
 4273 ttys000    0:00.00 (firefox-bin)
 4282 ttys000    0:00.00 (firefox-bin)
 4285 ttys000    0:00.00 (firefox-bin)
 4298 ttys000    0:00.00 (firefox-bin)
 4301 ttys000    0:00.00 (firefox-bin)
 4304 ttys000    0:00.00 (firefox-bin)
 4311 ttys000    0:00.00 (firefox-bin)
 4317 ttys000    0:00.00 (firefox-bin)
 4320 ttys000    0:00.00 (firefox-bin)
 4338 ttys000    0:00.00 (firefox-bin)
 4342 ttys000    0:00.00 (firefox-bin)
 4377 ttys000    0:03.85 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4394 ttys000    0:05.54 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4471 ttys000    0:06.08 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4581 ttys002    0:04.92 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4607 ttys002    0:04.33 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4626 ttys002    0:05.04 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground

我想一击杀死所有他们,有什么简单的方法吗? 谢谢。

I would like to killing all the firefox processes from command line.

For example:

MacPro:huangr$ ps -x | grep 'firefox'
 4147 ttys000    0:00.00 (firefox-bin)
 4177 ttys000    0:00.00 (firefox-bin)
 4234 ttys000    0:00.00 (firefox-bin)
 4273 ttys000    0:00.00 (firefox-bin)
 4282 ttys000    0:00.00 (firefox-bin)
 4285 ttys000    0:00.00 (firefox-bin)
 4298 ttys000    0:00.00 (firefox-bin)
 4301 ttys000    0:00.00 (firefox-bin)
 4304 ttys000    0:00.00 (firefox-bin)
 4311 ttys000    0:00.00 (firefox-bin)
 4317 ttys000    0:00.00 (firefox-bin)
 4320 ttys000    0:00.00 (firefox-bin)
 4338 ttys000    0:00.00 (firefox-bin)
 4342 ttys000    0:00.00 (firefox-bin)
 4377 ttys000    0:03.85 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4394 ttys000    0:05.54 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4471 ttys000    0:06.08 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4581 ttys002    0:04.92 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4607 ttys002    0:04.33 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground
 4626 ttys002    0:05.04 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground

I would like to kill all of them in one shot, any easy way to do that?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一曲爱恨情仇 2024-12-29 06:24:00
kill -9 $(ps -x | grep 'firefox' | awk '{print $1}')

应该做

kill -9 $(ps -x | grep 'firefox' | awk '{print $1}')

Should do it

萧瑟寒风 2024-12-29 06:24:00

这非常有效。

ps -ef | grep '[f]irefox' | awk '{print $1}' | xargs kill -9 ;

或者

ps -ef | awk '/[f]irefox/ {print $1}' | xargs kill -9 ;

This works perfectly.

ps -ef | grep '[f]irefox' | awk '{print $1}' | xargs kill -9 ;

or

ps -ef | awk '/[f]irefox/ {print $1}' | xargs kill -9 ;
你穿错了嫁妆 2024-12-29 06:24:00

旁注 -

Kill -9 是过度杀伤(没有双关语),因为它阻止被杀死的进程运行清理(例如,atexit() 调用,如 exit 和 _exit 之间的区别)。这可能是也可能不是 Firefox 的问题,但一般来说,只有在普通的“kill”失败后才考虑尝试“kill -9”。

Side note -

kill -9 is overkill (no pun intended) because it prevents the killed process from running cleanup (e.g., atexit() calls, like the difference between exit and _exit). It may or may not be a problem with firefox, but in general consider trying "kill -9" only after plain "kill" fails.

想你只要分分秒秒 2024-12-29 06:24:00

killall firefox-bin

killall -9 firefox-bin

如果需要,

killall firefox-bin

or

killall -9 firefox-bin

if necessary

孤城病女 2024-12-29 06:24:00

这应该可以做到 -

kill `awk '$4~/firefox/{print $1}' <(ps -x)`

或者在一般说明中,将此函数添加到您的启动脚本中 -

killp() {
awk -v pname="$1" '$4~/pname/{print $1}' <(ps -e) | xargs kill
}

测试:

[jaypal:~/Temp] sleep 100&
[1] 52530
[jaypal:~/Temp] sleep 100&
[2] 52531
[jaypal:~/Temp] killp sleep
[1]-  Terminated: 15          sleep 100
[2]+  Terminated: 15          sleep 100

This should do it -

kill `awk '$4~/firefox/{print $1}' <(ps -x)`

Or on a generic note, add this function to your startup script -

killp() {
awk -v pname="$1" '$4~/pname/{print $1}' <(ps -e) | xargs kill
}

Test:

[jaypal:~/Temp] sleep 100&
[1] 52530
[jaypal:~/Temp] sleep 100&
[2] 52531
[jaypal:~/Temp] killp sleep
[1]-  Terminated: 15          sleep 100
[2]+  Terminated: 15          sleep 100
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文