Explain the difference of wait () and waitpid () ? Identify the purpose of waitpid () ?
Solution. pid_t wait(int *stat_loc); pid_t waitpid(pid_t pid, int *stat_loc, int options);
The wait() and waitpid() functions allowthe calling process to obtain status information pertaining to one of its child processes.
The waitpid() function will behave identicallyto wait(), if the pid argument is (pid_t)-1 and the options argument is 0. Otherwise, its behaviour will be modified by the values of the pid andoptions arguments. The pid argument specifies a set of childprocesses for which status is requested. The waitpid() function will only return the status of a child process from this set: · If pid is equal to (pid_t)-1, statusis requested for any child process. In this respect, waitpid() is then equivalent to wait(). · If pid is greater than 0, it specifiesthe process ID of a single child process for which status is requested. · If pid is 0, status is requested forany child process whose process group ID is equal to that of the calling process. · If pid is less than (pid_t)-1, statusis requested for any child process whose process group ID is equal to the absolute value of pid.