Search code examples
cunixwait

Can a child execute waitpid() and wait() in C, Unix


In Unix, C. After a fork(), usually followed by a wait() or waitpid() to wait the child terminate. But can the child execute the wait()? The child doesn't have a _child_, so when it execute the wait(), what will happen?


Solution

  • There are no child proccess for the child proces so wait() will return -1. From the man page:

    wait(): on success, returns the process ID of the terminated child; on error, -1 is returned.