Your parent process can use the pid of the child process to detect that it is alive or exited (and can eliminate the error code, as well as errors with the error with the dead, see waitpid). You can use certain error codes or signals to notify the parent of specific cases of errors (for example, in a forked child before exec), but for a completely general child you cannot reserve any exit codes or signals (because the parent cannot determine if it has completed whether exec, and then the child exited with these values).
Another approach that is often used is to create a fd channel pair (see the "syscall" pipe) and pass one end to the child (usually the end of the record) and the other to the parent. A child can use this to send specific error codes to parents. And the parent can detect premature termination if the pipe is closed without receiving any data. There are some pitfalls: SIGPIPE will be sent to parents if it reads on a pipe without active authors, and using fd (except for stdin / stdout / stderr) in a child process can confuse some poorly written child processes (although close-on-exec can help fix this is).
In general, all the code I've seen to make fork + exec reliable is pretty hacky.
PT
source share