LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 10-27-2004, 04:02 AM   #1
shayer009
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..
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
 
Old 10-28-2004, 02:47 AM   #2
kuru
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, 02:57 AM   #3
shayer009
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

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

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


Reply


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 08:26 AM
Killing a child process from another child marri Programming 6 10-01-2004 08:08 PM
Killing child process coolfrog Programming 3 09-28-2004 03:58 PM
When I kill parent process, child isn't killed BengeBoy Linux - Software 0 08-19-2004 05:38 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 02:19 PM


All times are GMT -5. The time now is 01:27 AM.

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