How can I kill a process with a phrase in its name? [duplicate]

Solution 1:

If myName is the name of the process/executable which you want to kill, you can use:

pkill myName

pkill by default sends the SIGTERM signal (signal 15). If you want the SIGKILL or signal 9, use:

pkill -9 myName

If myName is not the process name, or for example, is an argument to another (long) command, pkill (or pgrep) may not work as expected. So you need to use the -f option.

From man kill:

-f, --full
              The pattern is normally only matched against the  process  name.
              When -f is set, the full command line is used.
NOTES
The process name used for matching is limited to the 15 characters present
   in the output of /proc/pid/stat.  Use the -f option to match  against  the
   complete command line, /proc/pid/cmdline.

So:

pkill -f myName

or

kill -9 $(pgrep -f myName)

Solution 2:

With a command's name use:

pkill -9 myscript

If you are looking for a string in the command line:

kill -9 $(ps ax | grep myName | fgrep -v grep | awk '{ print $1 }')

I have to warn you: the above command can send a SIGKILL signal to more than one process.