waitpid returns only -1 if an error occurs with waitpid . That is, if you give it the wrong pid or breaks, etc. If the child has a failure status, waitpid will succeed (return pid) and set ret to reflect the status of the child.
To determine the status of a child, use WIFEXITED(ret) and WEXITSTATUS(ret) . For instance:
if( waitpid( pid, &ret, 0 ) == -1 ) { perror( "waitpid" ); } else if( WIFEXITED( ret ) && WEXITSTATUS( ret ) != 0 ) { ; }
source share