Connecting Tech Pros Worldwide Forums | Help | Site Map

ANSI C - Determine if parent process ended before child

Newbie
 
Join Date: Oct 2007
Posts: 1
#1: Oct 3 '07
HELLU!!!....i'm juan...i'm argentinian....and i'm trying to write some code in "ANSI C" but i need to know if there's a way either through the pipe i created between 2 processes or through the process' pid if the PARENT process ended before the child process.....
anyone has any ideas???

Member
 
Join Date: Sep 2007
Location: New Delhi
Posts: 33
#2: Dec 21 '07

re: ANSI C - Determine if parent process ended before child


Quote:

Originally Posted by jonasclown

HELLU!!!....i'm juan...i'm argentinian....and i'm trying to write some code in "ANSI C" but i need to know if there's a way either through the pipe i created between 2 processes or through the process' pid if the PARENT process ended before the child process.....
anyone has any ideas???

Hi jonasclown,

For the purpose, you can use wait() or waitpid() function.

If you could not get it on then Either try posting with your trial code so that I will be in a better positon to help you or ask me and I will do the same.

Regards,
Raj Kumar Arora
Newbie
 
Join Date: Aug 2007
Posts: 28
#3: Dec 21 '07

re: ANSI C - Determine if parent process ended before child


After calling fork do something like following in your code for the child



Expand|Select|Wrap|Line Numbers
  1. while (getppid()!=1) //One is the pid of init and if the parent dies new ppid = 1
  2. {
  3.     sleep(10);   
  4. }
  5. //do the rest work here
  6. //THis will ensure that the child does not do any work until it is adopted by init
Reply