Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I kill a process by name instead of PID, on Linux? [duplicate]

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 

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 

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.)

like image 856
Paige Ruten Avatar asked Oct 02 '08 04:10

Paige Ruten


People also ask

How do I kill all processes with the same name?

You can use the pkill command. Note that myapp2 won't be killed as it has a different name. Show activity on this post. it will kill all processes starting with myap.


1 Answers

pkill firefox 

More information: http://linux.about.com/library/cmd/blcmdl1_pkill.htm

like image 186
shoosh Avatar answered Sep 18 '22 16:09

shoosh