ANSI C - Determine if parent process ended before child

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonasclown
    New Member
    • Oct 2007
    • 1

    ANSI C - Determine if parent process ended before child

    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???
  • rajarora
    New Member
    • Sep 2007
    • 33

    #2
    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

    Comment

    • smalpani
      New Member
      • Aug 2007
      • 29

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



      Code:
      while (getppid()!=1) //One is the pid of init and if the parent dies new ppid = 1
      {
          sleep(10);   
      }
      //do the rest work here
      //THis will ensure that the child does not do any work until it is adopted by init

      Comment

      Working...