LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to kill a Child and all its subsequent child process in C (https://www.linuxquestions.org/questions/programming-9/how-to-kill-a-child-and-all-its-subsequent-child-process-in-c-247798/)

shayer009 10-27-2004 03: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..
using
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

Shayer

kuru 10-28-2004 01: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 01: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

Shayer.

vinayhm 12-04-2007 12:40 AM

kill all childs of parent
 
Hi..
try this...

The syntax of kill command is

kill(pid,signal);

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 following...to kill all process having the SAME PROCESS ID ..should work for u.

kill(0,SIGTERM);


Cheers
Vins


All times are GMT -5. The time now is 02:25 AM.