#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    Wait(NULL) question


    For example, if I have a series of processes as follows,
    P1 fork P2
    P2 fork P3
    P3 fork P4.

    I call wait(NULL) in P3, P2 and P1 before terminating them.
    So when P4 terminates, is the order of termination P3, P2 then P1??
    Will wait(NULL) be affected by other processes' termination other than its own child?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,406
    Rep Power
    1871
    > Will wait(NULL) be affected by other processes' termination other than its own child?
    P1 can't terminate before P4, because there is a chain of wait()'s going on.

    So it will terminate in P4 P3 P2 P1 order.
    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

IMN logo majestic logo threadwatch logo seochat tools logo