I have a child process that is designed to exit under certain conditions, I have used exit(-2). But after calling WEXITSTATUS the value is around 256. If I use exit(2) the proper value is returned by WEXITSTATUS. Any reason why using a negative value in the exit call is doing this?
Asked
Active
Viewed 957 times
1
-
From `/usr/include/bits/waitstatus.h`, there is `#define __WEXITSTATUS(status) (((status) & 0xff00) >> 8)` which would convert `-2` to `255`, not `256`. Or maybe in your platform you have a different `waitstatus.h` header. – alvits Mar 21 '16 at 19:57
-
1Negative exit codes have little meaning because they are received as positive but wrong (e.g. -2 --> 254). Use a positive value, which for POSIX systems, can be 0-255. For some more discussion, see my answer here: http://stackoverflow.com/questions/36091166/return-1-vs-return-0-user-and-programmer/36094168#36094168 – Craig Estey Mar 21 '16 at 20:10