LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-16-2009, 08:34 AM   #1
laki47
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
Killing parent process


Hi,

Can I always kill all child processes in tree by killing the parent process? Is it "normal" to do it in that way?

Thank you
 
Old 07-16-2009, 09:27 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 285

Rep: Reputation: 61
Yes, if the parent and children are in the same process group. Otherwise no.
 
Old 07-17-2009, 04:29 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,524
Blog Entries: 27

Rep: Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175
Hello laki47

A simple question with a complex answer. AFAIK fpmurphy is essentially correct but there are at least two situations in which that is not the whole story.

Firstly the dreaded zombies! If a child process has terminated but its exit status has not been read by its parent then, when the parent is terminated, the kernel re-parents the child to the init process, process number 1. The child becomes a "zombie". Thus the child process has been killed (it is no longer executing) but it remains in the process table indefinitely.

Secondly, if the process group leader is a terminal and it is killed, the kernel will send the "hang up" signal (SIGHUP) to all the processes in the dead terminal process' group. By default, they die on receiving SIGHUP but they can be configured differently. See the nohup command for an example.

There may be other situations in which members of a group do not die when their group leader or parent is killed.

As for whether it is normal ... it is often done but there could be systems an which it is rarely done; it's a question of usage and signal handling. A process can be programmed to do whatever the programmer implemented on receipt of every signal except SIGKILL. SIGKILL cannot be ignored, a bit like death.

For more information http://www.win.tue.nl/~aeb/linux/lk/lk-10.html

Best

Charles
 
Old 07-17-2009, 05:05 AM   #4
vivek31be
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Rep: Reputation: 0
Killing all of the processes in a process group will kill the parent as well as children. That may not be what you wanted.
Also take a look at "killall" or "pkill". Both commands will kill a process based on the command name.
 
Old 07-17-2009, 09:02 AM   #5
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Quote:
Originally Posted by laki47 View Post
Hi,

Can I always kill all child processes in tree by killing the parent process? Is it "normal" to do it in that way?

Thank you
I've used this code to kill a parent process and its child processes.
Code:
pkill -P $( pgrep program/script )
Replace the red with the name of the program or script. If a program was started from a shell script, the above command will kill the shell script along with the program(s) that was started from it.

- Cheers

Last edited by dv502; 07-17-2009 at 09:19 AM.
 
  


Reply

Tags
parent, process


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
memory leak: Parent killing child process wkhoo Programming 12 06-04-2008 05:39 PM
Does killing the thread kill its parent process? piyush.kansal Programming 7 07-09-2007 08:11 PM
child process usses same amount of ram as parent process socialjazz Programming 7 10-19-2006 05:48 PM
how to make ppid of a process as init without killing its parent shantha Programming 10 12-17-2004 07:36 AM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM


All times are GMT -5. The time now is 03:47 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