22

按照名字杀死进程的四种方法

 3 years ago
source link: http://www.cnblogs.com/zhcpku/p/13796773.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

太长不看版:

匹配方式 模糊匹配 精确匹配 匹配命令 pgrep pidof kill命令 kill -9 $(pgrep <proc-name> ) kill -9 $(pidof <proc-name> ) 组合命令 pkill -9 <proc-name> killall -9 <proc-name>

以下是正文

按照名字杀死进程的四种方法

根据名字杀死进程的需求来自于同时杀死一组进程,如MPI程序的进程。杀死单个进程只需要 top 或者 ps 命令找到进程然后直接 kill -9 <pid> 就可以了。

要使用kill命令杀死进程,首先需要找出进程的pid。根据进程名称查找pid,有精确匹配和模糊匹配两种方式:

pidof
pgrep

得到精确进程名的方法参照杀死单个进程的办法,使用 top 或者 ps 命令。

拿到一组进程pid之后可以使用kill命令批量杀死:

kill -9 $(pidof <proc-name>)
kill -9 $(pgrep <proc-name>)

有两个命令,分别相当于 killpidof 或者 pgrep 命令的组合:

killall -9 <proc-name>
pkill -9 <proc-name>

这里用到的 -9 实际上指的是发送 SIGKILL 信号给进程,这是一种比较强力的结束信号,默认的是 -15 也就是 SIGTERM 信号。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK