10

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?

2 Answers 2

19

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
1
  • Neither one worked for me. I can't figure out how to kill Xvfb. ps -ef | egrep "Xvfb|PID" still shows it alive after both of those commands.
    – Ryan
    Aug 16, 2017 at 15:25
2

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
3
  • Unfortunately no, they're all subprocesses, fork()ed I think. They certainly all have different PIDs though. Oct 8, 2009 at 2:59
  • 1
    Not PID ( Process id ), Process Group ID, PGRP.... Oct 8, 2009 at 11:08
  • 1
    oh, jeez, I misread your answer. But, also, they aren't all in the same PGRP. But, thanks, I didn't know that trick about the negative args (in the first sentence of the manpage...) Dec 20, 2009 at 7:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .