Single Process#

If you want kill a running process called, you could do

$ ps | grep main | grep py
$ kill -9 <pid>

but that's a hassle. To do it in one step, you can do

$ kill -9 `ps | grep main | grep py | cut -f 1 -d" "`

Multiple Processes#

If you have many python scripts with 'matterhorn' in the path (visible by doing "ps auxwww") then you can do

$ ps auxwww | grep python | grep matterhorn | awk '{print $2}' | xargs kill -9

What this does is:

  • do a 'ps' with full paths displayed
  • grep for python
  • grep for matterhorn
  • filter out the second column which is the PID
  • 'kill -9' all PIDs

CategoryComputing.Linux.Shell - CategoryComputing.Mac.Shell