-   Programming (
-   -   How to kill a Child and all its subsequent child process in C (

shayer009 10-27-2004 04:02 AM

How to kill a Child and all its subsequent child process in C
wrote a program that do the following.

1. It fork() and create a child process
2. Child process use execl() command to run a java program..
execl("java -jar st.jar");
3. When i killed the child process programmatically using C system functions it only kills the child process. But the Java process which is created by the child process keeps on running at the backend.

Can you please inform me how can i kill these child of child processes.
when i kill the child process.

I tried Kill commands doesnot work... IS there any command to kill the entire processtree.

Kind Regards


kuru 10-28-2004 02:47 AM

You can use "pidof" program
$> kill -9 `pidof -x java`

'-x' option of 'pidof' program is to kill its child process.

shayer009 10-28-2004 02:57 AM

Hello Kuru
Thanks for your reply. I am new to linux programming.

Where i have to define the PARENT PID when i want to kill all its child
Can you please explain a bit more of the command you give me

Kind Regards


vinayhm 12-04-2007 01:40 AM

kill all childs of parent
try this...

The syntax of kill command is


As u want to kill ALL children u created by saying execl("java...") after forking.

The Process Group Id, of the "Parent Process" (which forked) and the child
created will same.

so do the kill all process having the SAME PROCESS ID ..should work for u.



All times are GMT -5. The time now is 11:36 PM.