如何通过名称而不是PID杀死进程? [英] How can I kill a process by name instead of PID?

查看:204
本文介绍了如何通过名称而不是PID杀死进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,当我尝试启动Firefox时,显示"Firefox进程已在运行".所以我必须这样做:

Sometimes when I try to start Firefox it says "a Firefox process is already running". So I have to do this:

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(或其他任何字符串),并杀死输出中的所有进程:

What I'd like is a command that would do all that for me. It would take an input string and grep for it (or whatever) in the list of processes, and would kill all the processes in the output:

jeremy@jeremy-desktop:~$ killbyname firefox

我尝试在PHP中执行此操作,但exec('ps aux')似乎仅显示PHP脚本本身中已使用exec()执行的进程(因此,它显示的唯一进程是其自身.)

I tried doing it in PHP but exec('ps aux') seems to only show processes that have been executed with exec() in the PHP script itself (so the only process it shows is itself.)

推荐答案

pkill firefox

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

这篇关于如何通过名称而不是PID杀死进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆