Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-27-2004, 03:02 AM   #1
LQ Newbie
Registered: Oct 2004
Posts: 3

Rep: Reputation: 0
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

Old 10-28-2004, 01:47 AM   #2
LQ Newbie
Registered: Oct 2004
Location: korea
Posts: 11

Rep: Reputation: 0
You can use "pidof" program

$> kill -9 `pidof -x java`

'-x' option of 'pidof' program is to kill its child process.
Old 10-28-2004, 01:57 AM   #3
LQ Newbie
Registered: Oct 2004
Posts: 3

Original Poster
Rep: Reputation: 0
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

Old 12-04-2007, 12:40 AM   #4
LQ Newbie
Registered: Dec 2007
Posts: 1

Rep: Reputation: 0
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.




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
Killing a child process from another child marri Programming 6 10-01-2004 07:08 PM
Killing child process coolfrog Programming 3 09-28-2004 02:58 PM
When I kill parent process, child isn't killed BengeBoy Linux - Software 0 08-19-2004 04:38 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:56 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration