Code to create an orphan process?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neozonka
    New Member
    • Mar 2010
    • 6

    Code to create an orphan process?

    Can anyone help me in writing the code to create an orphan process......?? ??
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    You mean to process which will be addopted by init (as i know on most unix-like systems every orphan process is addopted by init)?

    Comment

    • neozonka
      New Member
      • Mar 2010
      • 6

      #3
      Yeah ....i need the code to do the same......can u plz provide ????

      Comment

      • rski
        Recognized Expert Contributor
        • Dec 2006
        • 700

        #4
        You want code in C? bash? or any

        Comment

        • neozonka
          New Member
          • Mar 2010
          • 6

          #5
          I need the code in C.

          Comment

          • rski
            Recognized Expert Contributor
            • Dec 2006
            • 700

            #6
            Code:
            #include <stdio.h>
            #include <unistd.h>
            #include <sys/types.h>
            #include <stdlib.h>
            #include <sys/wait.h>
            
            int main(){
                    pid_t i;
            
                    i=fork();
            
                    if (i==0){
                    while (1){
                            printf("child process pid = %d, ppid=%d\n",(int)getpid(), (int)getppid());
                            sleep(3);
                    }
            
                    }else{
            
                            printf("parent has finished");
            
            
                    }
                    return 0;
            }
            It creates process which is addopted by init when parent has finished. Child process is working in unfinite loop (but you can of course change it).
            Is that what you want?

            Comment

            • neozonka
              New Member
              • Mar 2010
              • 6

              #7
              Yeahhh....Thanx Buddyyyy

              Comment

              Working...