If any process has more than one child processes, then after calling wait(), parent process has to be in wait state if no child terminates.
If only one child process is terminated, then return a wait() returns process ID of the terminated child process.
If more than one child processes are terminated than wait() reap any arbitrarily child and return a process ID of that child process.
When wait() returns they also define exit status (which tells our, a process why terminated) via pointer, If status are not NULL.
If any process has no child process then wait() returns immediately “-1”.
NOTE: “This codes does not run in simple IDE because of environmental problem so use terminal for run the code”
Examples: here