What does this line do ?
while (wait(NULL)== -1);
This line is written inside a parent process after fork.
What does this line do ?
while (wait(NULL)== -1);
This line is written inside a parent process after fork.
EDIT: I stand corrected! Thanks @interjay
From the wait man page:
wait() and waitpid() The wait() system call suspends execution of the calling process until one of its children terminates. The call wait(&status) is equivalent to: waitpid(-1, &status, 0)
From wait man page
wait(): on success, returns the process ID of the terminated child; on error, -1 is returned.
So what the code is doing here is waiting for any child process to terminate with an error, and we are ignoring the return value. (passing in a NULL ptr instead of a ptr to an int which the return value would be stored in).