waitpid
only returns -1 if an error occurs with waitpid
. That is, if you give it an incorrect pid, or it is interrupted, etc. If the child has a failing exit status, waitpid will succeed (return the pid) and set ret
to reflect the status of the child.
To determine the status of the child, use WIFEXITED(ret)
and WEXITSTATUS(ret)
. For example:
if( waitpid( pid, &ret, 0 ) == -1 ) {
perror( "waitpid" );
} else if( WIFEXITED( ret ) && WEXITSTATUS( ret ) != 0 ) {
; /* The child failed! */
}