LinuxQuestions.org
Register a domain and help support LQ
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 11-18-2010, 09:07 AM   #1
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 75

Rep: Reputation: 5
Can a child process kill the parent process ?


Is it possible to kill a parent process from child ?
I just want to handle an error condition where a process has to launch the same process once more and then get killed by itself..
Is it possible/?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-18-2010, 10:02 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
Quote:
Originally Posted by sree_ec View Post
Is it possible to kill a parent process from child ?
I just want to handle an error condition where a process has to launch the same process once more and then get killed by itself..
Is it possible/?
Certainly. For example, open a terminal and do this:

Code:
$ ps
  PID TTY          TIME CMD
27469 pts/3    00:00:00 bash
27788 pts/3    00:00:00 ps
$ bash
$ ps
  PID TTY          TIME CMD
27469 pts/3    00:00:00 bash
27804 pts/3    00:00:00 bash
27840 pts/3    00:00:00 ps
$ kill -KILL ${PPID}
And you can kill the parent bash (pid=27469) from the child bash (pid=27804).
 
1 members found this post helpful.
Old 11-18-2010, 11:05 AM   #3
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 75

Original Poster
Rep: Reputation: 5
So Can I do it from a c program as well??
 
Old 11-18-2010, 11:18 AM   #4
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,528
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Yes but why not try it?
 
2 members found this post helpful.
Old 11-19-2010, 03:02 AM   #5
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,619
Blog Entries: 29

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Quote:
Originally Posted by sree_ec View Post
So Can I do it from a c program as well??
Checkout the following code and read up the coloured functions in Google/man pages.
Code:
#include <stdio.h> 
#include <unistd.h>

int main()
{
  pid_t pID = fork();

  /* child process */
  if (pID == 0)
    {
      printf ("\nReady to murder the parent!\n");
      kill (getppid(), 9);
    }
  /* parent process */
  else
    {
      printf ("\nLet the child execute first!\n");
      wait(0);
    }
}

Last edited by TheIndependentAquarius; 11-19-2010 at 05:26 AM. Reason: typo
 
Old 11-19-2010, 06:22 AM   #6
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 75

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by anishakaul View Post
Checkout the following code and read up the coloured functions in Google/man pages.
Code:
#include <stdio.h> 
#include <unistd.h>

int main()
{
  pid_t pID = fork();

  /* child process */
  if (pID == 0)
    {
      printf ("\nReady to murder the parent!\n");
      kill (getppid(), 9);
    }
  /* parent process */
  else
    {
      printf ("\nLet the child execute first!\n");
      wait(0);
    }
}
I tried with my program already ..But still , thanks for the reply [ I'm not rude ]...
 
Old 11-19-2010, 06:40 AM   #7
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,619
Blog Entries: 29

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Yeah, I noticed the thread marked SOLVED but then you had not posted the solution ? It is always better to post the solution so that others can benefit too!
 
Old 11-19-2010, 06:47 AM   #8
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,619
Blog Entries: 29

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
and secondly I would like to request you to modify your thread title to something more meaningful like this:
Quote:
Can a child process kill the parent process ?
A thread with a proper title comes up in Google searches and thus others can benefit too.
 
Old 11-20-2010, 05:37 AM   #9
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 75

Original Poster
Rep: Reputation: 5
Thumbs up

Quote:
Originally Posted by anishakaul View Post
and secondly I would like to request you to modify your thread title to something more meaningful like this:
A thread with a proper title comes up in Google searches and thus others can benefit too.
Accepted!
 
1 members found this post helpful.
  


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
Sending Signal from Child Process to Parent Process : Not getting desired output thelink123 Linux - General 4 10-26-2012 09:05 PM
child process usses same amount of ram as parent process socialjazz Programming 7 10-19-2006 05:48 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
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 06:07 AM


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