C – Retrieving a child’s exit status that is larger than 8 bits

I don’t think that what you are trying to accomplish it’s possible, because in Linux (actually i think it’s UX specific), a process exit code is an 8-bit number: 0-255 (and as a convention, 0 means success, anything else means error) and lots of stuff rely on this fact (including the macros you used). Take the following piece of code:

// a.c
int main() {
    return 257;
}

If you compile it (gcc a.c), and run the resulting executable (a.out) checking (echo $?) its exit code (that will be truncated by the OS; hmm or is it the shell?) it will output 1 (wrap around arithmetic): 257 % 256 = 1.

As an alternative as you mentioned, you could use pipe (this post is pretty descriptive) or sockets (AF_UNIX type).

Leave a Comment