I need to kill a process that contains myName
in its description. Currently I'm doing:
ps -ax |grep myName
I see PID
kill -9 PID
How can I do the same with one command without entering the PID?
I need to kill a process that contains myName
in its description. Currently I'm doing:
ps -ax |grep myName
I see PID
kill -9 PID
How can I do the same with one command without entering the PID?
If
myName
is the name of the process/executable which you want to kill, you can use:pkill
by default sends theSIGTERM
signal (signal 15). If you want theSIGKILL
or signal 9, use:If
myName
is not the process name, or for example, is an argument to another (long) command,pkill
(orpgrep
) may not work as expected. So you need to use the-f
option.From
man kill
:So:
or
With a command's name use:
If you are looking for a string in the command line:
I have to warn you: the above command can send a
SIGKILL
signal to more than one process.With
pkill
and sending signal 9, you can kill process by name:There are two very neat commands
pgrep
andpkill
that allow entering search term or part of the command name , and it will either provide the PID(s) of the process or (in case ofpkill
) kill that process.Running the same command with
pkill
and-f
flag will close all the firefox windows.The
-f
flag is needed specifically to search through the full command-line of a process.You could do a simple
for loop
over all the PID's associated with the specific process name, like this:This will kill all processes that contain the word:
myName
.