I have a question about program exit state in Linux. In my program, I fork a child process and invoke waitpid to reap it. When waitpid returns, I wanna check exit state of my child process. I turn to manual for help and find that the second argument of waitpid will hold exit state and I can use macro WEXITSTATE to read it. However, this macro just extract least significant 8 bits of the real exit state, while in manual of function exit(int ret_val), it will exit with ret_val & 0x377, instead of least significant 8 bits.
My question is, where is the other more bits? Do we simply drop them? Why Linux employ this strategy? Doesn’t this implementation introduce trouble to our program?
Thanks and Best Regards.
I think you will find that
0x377is really, or should have been,0377.It’s octal, so 3778 is 8 bits.