Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-16-2009, 09:34 AM   #1
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
Killing parent process


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, 10:27 AM   #2
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
Yes, if the parent and children are in the same process group. Otherwise no.
Old 07-17-2009, 05:29 AM   #3
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

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


Old 07-17-2009, 06:05 AM   #4
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, 10:02 AM   #5
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Originally Posted by laki47 View Post

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.
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 10:19 AM.


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

All times are GMT -5. The time now is 08:21 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration