5

Here is output from ps:

$ ps aux | grep blob
ubuntu    4286  0.0  0.1  34748  9592 ?        S    Jan14   0:00 /usr/bin/python /usr/local/bin/pynt start_blob_reader
ubuntu    4287  0.0  0.1  34748  9596 ?        S    Jan14   0:00 /usr/bin/python /usr/local/bin/pynt start_blob_reader
ubuntu    4288  0.0  0.0   4444   656 ?        S    Jan14   0:00 /bin/sh -c python -m blob_manager blob
ubuntu    4289  1.2  0.2  65512 20668 ?        S    Jan14 1974:18 python -m blob_manager blob
ubuntu    4290  0.0  0.0   4444   656 ?        S    Jan14   0:00 /bin/sh -c python -m blob_manager blob
ubuntu    4291  1.2  0.2  65404 20624 ?        S    Jan14 1978:24 python -m blob_manager blob
ubuntu   19849  0.0  0.0  10464   896 pts/0    S+   05:43   0:00 grep blob

What is the easiest to kill these jobs (except 19849 because it is the grep process itself) via shell scripting?

Either bash or zsh is OK.

4

Use pkill:

pkill blob

That would kill all processes matching the pattern blob.

Another approach would be killall, but you should call it with -r so that the pattern is interpreted as a regex:

killall -r blob
1

You should get all the PIDs and kill 'em all:

kill $(ps -ef|grep -v grep |grep java |awk '{print $2}'|tr '\n' ' '); echo

or make it more verbose:

netikras@netikras-PC ~ $ #ps -ef |grep -v grep |grep java |while read line; do echo "$line" |awk '{$1=$3=$4=$5=$6=$7=""; print "Killing: "$0"\n"}'; kill $(echo $line|awk '{print $2}') && echo KILLED || echo FAILED ; done
netikras@netikras-PC ~ $ 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.