问题描述
我想用一个简单的命令杀死一个进程/脚本.目前我做以下事情
I'd like to kill a process/script with a simple command using. At the moment I do the following
ps -ef | grep myscriptname
kill 123456
但是有没有办法将这 2 个命令组合在一起,这样我就不需要查看和手动编写 pid,就像这样 kill grep myscriptname
?
But is there a way to maybe combine the 2 command together so I don't need to look and manually write the pid, something like this kill grep myscriptname
?
推荐答案
你想要pkill
:
pkill myscriptname
在某些系统上有一个名为 killall
的类似工具,但要小心,因为在 Solaris 上它确实会杀死一切!
On some systems there is a similar tool called killall
, but be careful because on Solaris it really does kill everything!
请注意,还有 pgrep
可用于替换 ps |grep
管道:
Note that there is also pgrep
which you can use to replace your ps | grep
pipeline:
pgrep myscriptname
它会为您打印 PID,仅此而已.
It prints the PID for you, and nothing else.
这篇关于如何使用“kill"结合“grep"杀死进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!