Thread: help with waitpid()

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    101

    Question help with waitpid()

    Hi!

    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:
    Code:
    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
    Location
    The edge of the known universe
    Posts
    37,537
    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