One of the best features in Linux is the way you can control processes from the command line, so if you have an application that locks up your GUI, you can always SSH over from another machine and just kill the offending process.
Linux中最好的功能之一是可以从命令行控制进程的方式,因此,如果您有一个可锁定GUI的应用程序,则始终可以从另一台计算机上进行SSH SSH,而只是杀死有问题的进程。
The problem is that if you are killing the same process repeatedly, it’s very tedious to have to figure out the process ID every single time so that you can kill it… so here’s the easier way to do it.
问题是,如果您要反复杀死同一进程,则必须每次都弄清进程ID,以便可以杀死它,这很繁琐……所以这是更简单的方法。
The Old Way
旧方法
The classic way of killing processes meant you’d first need to use the ps command piped through grep to find the process you are trying to kill:
杀死进程的经典方法意味着您首先需要使用通过grep传递的ps命令来查找您要杀死的进程:
$ ps -ef | grep swiftfoxgeek 7206 22694 0 Dec04 ? 00:00:00 /bin/sh /opt/swiftfox/swiftfoxgeek 7209 7206 0 Dec04 ? 00:00:00 /bin/sh /opt/swiftfox/run-mozilla.sh /opt/swiftfox/swiftfox-bingeek 7213 7209 0 Dec04 ? 00:04:29 /opt/swiftfox/swiftfox-bingeek 14863 14224 0 18:19 pts/4 00:00:00 grep swiftfox
$ ps -ef | grep swiftfoxgeek 7206 22694 0 Dec04? 00:00:00 / bin / sh / opt / swiftfox / swiftfoxgeek 7209 7206 0 Dec04? 00:00:00 / bin / sh /opt/swiftfox/run-mozilla.sh / opt / swiftfox / swiftfox-bingeek 7213 7209 0 Dec04? 00:04:29 / opt / swiftfox / swiftfox-bingeek 14863 14224 0 18:19 pts / 4 00:00:00 grep swiftfox
Then to kill the process, you’d have to use the kill command:
然后,要终止该进程,您必须使用kill命令:
$ kill 7206
$杀死7206
The New Way
新方法
Instead of going through all of that, you can simply use the pkill command if you already know the process name or part of it.
如果您已经知道进程名称或进程名称的一部分,则可以简单地使用pkill命令来代替全部操作。
$ pkill swiftfox
$ pkill swiftfox
It’s as simple as that. You should note that pkill will kill all processes matching the search text, in this case swiftfox
就这么简单。 您应该注意pkill将杀死所有与搜索文本匹配的进程,在这种情况下为swiftfox
If you want to see what process names are matched before using the pkill command, you can use the pgrep command. Passing the -l switch tells pgrep to show the process name as well.
如果要在使用pkill命令之前查看匹配的进程名称,可以使用pgrep命令。 传递-l开关告诉pgrep也显示进程名称。
$ pgrep -l swiftfox7206 swiftfox7213 swiftfox-bin
$ pgrep -l swiftfox7206 swiftfox7213 swiftfox-bin
Swiftfox seems to crash on me a lot, so I’ve unfortunately had to use this command a lot lately.
Swiftfox似乎使我崩溃了很多,因此不幸的是我最近不得不频繁使用此命令。
翻译自: https://www.howtogeek.com/howto/linux/kill-linux-processes-easier-with-pkill/