Thread: help with waitpid()

  1. #1
    Registered User
    Join Date
    Apr 2008

    Question help with waitpid()


    I'm doing a program where I need to wait until a specific child process ends to go on.
    I think this should be easy but somehow the parent doesn't wait for the child to die.

    My code is as follows:
    waitpid(p[1], NULL, WNOHANG);
    where p[1] is where I have the pid number stored.

    What I think is happening is -> the call checks if the child is dead and moves on even if the child isn't dead.
    What I want to happen -----> the call checks if the child is dead and if it isn't it stops there until the child dies.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well that's what NOHANG means.
    The parent doesn't hang around waiting for the child to die.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seeking for exercises
    By smoking81 in forum Linux Programming
    Replies: 7
    Last Post: 09-14-2008, 06:46 PM