In bash:
1 |
kill $(ps aux | grep 'xxxx' | awk '{print $2}') |
Details on its workings are as follows:
- The
ps
gives you the list of all the processes. - The
grep
filters that based on your search string - The
awk
just gives you the second field of each line, which is the PID. - The
$(x)
construct means to executex
then take its output and put it on the command line. The output of thatps
pipeline inside that construct above is the list of process IDs so you end up with a command likekill 1234 1122 7654
.
Source: http://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex