Summer_More_More_Tea
Summer_More_More_Tea

Reputation: 13356

Program exit state

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.

Upvotes: 3

Views: 1183

Answers (3)

DigitalRoss
DigitalRoss

Reputation: 146093

I think you will find that 0x377 is really, or should have been, 0377.

It's octal, so   3778   is 8 bits.

Upvotes: 6

geekosaur
geekosaur

Reputation: 61389

Unix/POSIX only supports 8 bits. 10 bits would be an odd (in both mathematical and logical senses) value, so I'd have to agree with @DigitalRoss.

Upvotes: 0

Jason
Jason

Reputation: 32510

Exit return values are only suppose to be between 0 and 255 per the POSIX spec. You shouldn't be returning values higher than that (in other words a POSIX-compliant OS will only be concerned with the lower eight-bits of your exit return value, and that's all that will be passed to the parent process).

Upvotes: 2

Related Questions