If waitpid is called and no child processes have been created, then waitpid returns -1 immediately and sets the globally defined int variable errno to an error code: ECHILD
Similarly, if the pid is not equal to some child's process id, waitpid returns -1 and sets errno to ECHILD.
Otherwise, the behavior depends on the pid and the option parameter.
With option = 0, waitpid waits for some child in the process group to terminate (either normally or abnormally).
For option = WNOHANG, waitpid returns 0 immediately if no child has terminated when waitpid is called.
For option = WUNTRACED, waitpid waits for a child in the process group that has terminated or stopped.
For option = WNOHANG | WUNTRACED, waitpid also waist for terminated or stopped child in the process group, but returns 0 immediately if there is no stopped or terminated child in the process group.
If the return value is not 0 or -1, it is the pid of the selected process in the process group.