如何在 Linux 上按名称而不是 PID 杀死进程? [英] How can I kill a process by name instead of PID, on Linux?

查看:52
本文介绍了如何在 Linux 上按名称而不是 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

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

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