Thread: orphans

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    61

    orphans

    In a UNIX system, what happens to child processes when their parent processes exit (while the child process still has a thread of execution). i.e. (not sure how UNIX system call names vary amongst different *nixs): exec(some child process from main) and don't call wait(pid) and have an exit statement right after. Then for the child process have some large amount of code to execute (so regardless of the scheduling algorithm there should be a context switch back to main with some code still left for the child). Since the main process isn't going to wait for the child process it should exit immediately, however the child process still has some code to execute; does the child process simply terminate on the spot or will the kernel allow the child process to finish whatever it was doing and if so then who is now the parent process of this child?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > what happens to child processes when their parent processes exit
    It just carries on doing whatever it was doing, until it arrives at its normal exit condition, crashes due to some bug, or is killed by some external event.

    > and if so then who is now the parent process of this child?
    I think the init process becomes the new parent.
    You can test this by calling getppid() from within your child process, after the demise of the original parent.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    thanks for the info.!

Popular pages Recent additions subscribe to a feed