See wait
manual:
If status is not NULL,
wait()
andwaitpid()
store status information in the int to which it points. This integer can be inspected with the following macros (which take the integer itself as an argument, not a pointer to it, as is done inwait()
andwaitpid()
!):
WIFEXITED(status)
returnstrue
if the child terminated normally, that is, by callingexit(3)
or_exit(2)
, or by returning frommain()
.
WEXITSTATUS(status)
returns the exit status of the child. This consists of the least significant 8 bits of the status argument that the child specified in a call toexit(3)
or_exit(2)
or as the argument for a return statement inmain()
. This macro should only be employed ifWIFEXITED
returnedtrue
.
Your issue is unrelated to golang, you just have to use these macros to extract the status code:
if (WIFEXITED(status)) {
printf("process %d status: %d\n", pid, WEXITSTATUS(status));
}