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.

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

  1. Kill all processes accessing the a particular file/folder
  2. Kill all processes listening on a particular port
  3. Why sometimes kill does not work
  4. List processes by memory usage
  5. Display the top 10 processes used up the most of the memory

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>