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
pkill firefox
More information: http://linux.about.com/library/cmd/blcmdl1_pkill.htm
awk oneliner, which parses the header of ps
output, so you don't need to care about column numbers (but column names). Support regex. For example, to kill all processes, which executable name (without path) contains word "firefox" try
ps -fe | awk 'NR==1{for (i=1; i<=NF; i++) {if ($i=="COMMAND") Ncmd=i; else if ($i=="PID") Npid=i} if (!Ncmd || !Npid) {print "wrong or no header" > "/dev/stderr"; exit} }$Ncmd~"/"name"$"{print "killing "$Ncmd" with PID " $Npid; system("kill "$Npid)}' name=.*firefox.*
You can kill processes by name with killall <name>
killall sends a signal to all processes running any of the specified commands. If no signal name is specified, SIGTERM is sent.
Signals can be specified either by name (e.g. -HUP or -SIGHUP ) or by number (e.g. -1) or by option -s.
If the command name is not regular expression (option -r) and contains a slash (/), processes executing that particular file will be selected for killing, independent of their name.
But if you don't see the process with ps aux
, you probably won't have the right to kill it ...
The easiest way to do is first check you are getting right process IDs with:
pgrep -f [part_of_a_command]
If the result is as expected. Go with:
pkill -f [part_of_a_command]
Using #killall
command:
#killall -9 <processname>
ps aux | grep processname | cut -d' ' -f7 | xargs kill -9 $