[Ilugc] Killing an enitre process tree

  • From: lug@xxxxxxxxxxxxxxxxxx (Chandrashekar Babu)
  • Date: Sun Oct 29 19:52:46 2006

Hi,  

 The situation is so. Py_Prog1 --> Shell --> Prog2. Now I want to kill
 both Shell and Prog2. How do I do that?

You can try using killpg() system call or trying the kill() system call with 
the negated PID. 

Yet, there is no reliable/straight-forward mechanism on UNIX/Linux to
kill an entire process-tree. It is very likely that one of the child process
deep down the process hierarchy could detach from the current
 process-group/session by performing a setsid() system call and you 
will have no direct control over it.

Iterating/Recursing down the process tree (which is complicated) 
determining the process-id relating to their parent's process-id/hierarchy 
and killing one by one could be the only way out.

Good luck :-)

--
Chandrashekar Babu.,
FOSS Technologist,
http://www.chandrashekar.info/

Other related posts: