LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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: 76

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: 139Reputation: 139
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: 76

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: Debian
Posts: 8,578
Blog Entries: 31

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

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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 Aquarius_Girl; 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: 76

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
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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: 76

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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:07 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration