previous | start | next

Wait for the Child to Finish

The shell can wait for the child to terminate by calling waitpid:

    int n;
    int status;
    ...
    n = waitpid(child_pid, &status, 0);

This would cause the parent (e.g., the shell) to wait until the child process whose pid is child_pid to terminate.

The last parameter specifies options for waiting; 0, means wait for the child to terminate, but other options can specify wait until the child's state changes, not just termination.

A successful call to waitpid will reap the child process; free its process table entry and discard all information about the process.



previous | start | next