simple examples of how to

Monday, November 7, 2011

[Linux] killall by shell script

As the another example of using xargs, you can do the following if your linux box does not have killall.

$ ps ax | grep killme-process | awk '{print $1}' | xargs kill

The above command files the process, killme-process, and kills it.
The chain of pipelining is the following.

First, ps ax gives all the name of processes where the first column is the process ID.
Second, grep killme-process finds the processes with the name, killme-process.
Third, awk only prints the first column ($1) which is the process ID.
Fourth, xargs turns the list of process IDs as the input arguments of kill.
Finally, kill kills them.


No comments:

Post a Comment