有时当我试图启动Firefox时,它会提示“Firefox进程已经在运行”。所以我必须这样做:

jeremy@jeremy-desktop:~$ ps aux | grep firefox
jeremy    7451 25.0 27.4 170536 65680 ?        Sl   22:39   1:18 /usr/lib/firefox-3.0.1/firefox
jeremy    7578  0.0  0.3   3004   768 pts/0    S+   22:44   0:00 grep firefox
jeremy@jeremy-desktop:~$ kill 7451

我想要的是一个能为我做这一切的命令。它将在进程列表中获取一个输入字符串和grep(或其他),并将杀死输出中的所有进程:

jeremy@jeremy-desktop:~$ killbyname firefox

我尝试在PHP中这样做,但exec('ps aux')似乎只显示已在PHP脚本本身的exec()执行的进程(所以它显示的唯一进程是本身)。


当前回答

奇怪,但我还没见过这样的解决方案:

kill -9 `pidof firefox`

它也可以杀死多个进程(多个pid),比如:

kill -9 `pgrep firefox`

我更喜欢pidof,因为它有单行输出:

> pgrep firefox
6316
6565
> pidof firefox
6565 6316

其他回答

pkill firefox

更多信息:http://linux.about.com/library/cmd/blcmdl1_pkill.htm

使用killall命令:

killall processname

使用-9或-KILL强制终止程序(选项类似于kill命令)。

用grep杀死:

kill -9 `pgrep myprocess`

奇怪,但我还没见过这样的解决方案:

kill -9 `pidof firefox`

它也可以杀死多个进程(多个pid),比如:

kill -9 `pgrep firefox`

我更喜欢pidof,因为它有单行输出:

> pgrep firefox
6316
6565
> pidof firefox
6565 6316

我通常使用killall命令。

有关该命令的详细信息,请查看此链接。