Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Apr 212010
 

Best way to kill all child processes forked by a given program

Answer:

Firstly, find the process group leader (i.e. master process that forked other processes) of the program, e.g. apache2

# sudo ps x -o  "%p %r %y %x %c " | grep apache2 

14787 14787 ?        00:00:00 apache2

To verify if it is the process leader.

# pgrep apache2 | sort -n | head -n1 
14787 

To issue kill to all the members in the process group

# kill -9 -14787

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>