2012-05-03 The termination status of processes in Unix, as retrieved by wait(2), is pretty packed in order to save space. That's historic and a bit difficult. I fully understand that people don't remember the exact bit layout. (Reminder: 8 bits exit code, 1 bit core, 7 bits signals.) POSIX had agreed that it's difficult to remember and thus introduced macros to extract the particular portions from the int. Symbolic macro names are much better than magic bit fiddling. Well, I wanted to know which bits are which, without searching the web. The man page of wait(2) didn't help. Maybe they want the people to forget the bit layout and thus have them use the macros instead. As for instance WEXITSTATUS is a macro, I can simply look it up in the header file -- great! view /usr/include/sys/wait.h Unfortunately, and maybe that's the main reason why people don't read the header files anymore, glibc's header files are flooded with abstractions and indirections. They are surely no fun to read. Though, in the present case it wasn't all that bad. One step deeper I found the information I was looking for: view /usr/include/bits/waitstatus.h The file includes the following lines: 28 /* If WIFEXITED(STATUS), the low-order 8 bits of the status. */ 29 #define __WEXITSTATUS(status) (((status) & 0xff00) >> 8) Huh ... doen't the code check the high-order byte, but the com- ment talks about the low-order byte? I was confused. Eventually I realized that the comment simply doesn't match to the code. The second part of the comment (after the comma) talks about the first part of the comment, but not about the code line below. Whereas in the following lines: 31 /* If WIFSIGNALED(STATUS), the terminating signal. */ 32 #define __WTERMSIG(status) ((status) & 0x7f) The second part of the comment talks about the code below, but not about the first part of the comment. By substituting ``low-order'' with ``high-order'' consistency would be restored. That's probably how it should be. Explanation: WIFEXITED() checks the low-order (right-most) byte for being zero (to be exact: ignoring the core bit). I.e. no signal killed the process. Hence, the child terminated normally. If so, then the exit code (the high-order byte) can be retrieved with WEXITSTATUS() and evaluated. The code is glibc-2.12.2. (btw: Can anyone tell me why the directory name `include' was not shortened to `inc'?) http://marmaro.de/lue/ markus schnalke