Possible to send kill signal to all processes with a given ppid?
I have found myself having to regularly send kill -STOP
one million processes, but they all come from the same parent. Is there a smarter way to do this?
Try pkill
:
pkill -STOP -P the_ppid
If you don't have pkill
, there's an alternative:
ps -o pid --ppid the_ppid --no-heading | xargs kill -STOP
They might all be in the same process group? if that is the case, you can just use regular old kill command, and make the pid negative.
So to find the process group of all the apache processes:
$ sudo ps -e -o cmd,pgrp | grep apache
/usr/sbin/apache2 -k start 24065
/usr/sbin/apache2 -k start 24065
/usr/sbin/apache2 -k start 24065
/usr/sbin/apache2 -k start 24065
Then to send a signal to the whole process group:
$ sudo kill -KILL -24065