What is the difference between "termination status" and "end status" as returned from waitpid?

Viewed 525

In Operating Systems Design and Implementation by Andrew S. Tanenbaum and Albert S. Woodhull, there's the following fragment:

"[...] consider exit, which processes should use when they are finished executing. It has one parameter, the exit status (0 to 255), which is returned to the parent via statloc [as in waitpid(int, int *statloc, int)] in the waitpid system call. The low-order byte of status contains the termination status, with 0 being normal termination and the other values being various error conditions. The high-order byte contains the child's exit status (0 to 255)."

So, what's the difference between the concepts?

2 Answers

The exit status refers to the value that a processes passed to the exit function (or returned from main) on normal program termination.

The termination status refers to what caused the program to end or stop. In other words, whether it exited normally (as mentioned above), or was terminated by a signal. This can also indicate if the processes was stopped (but not terminated) by a signal, or if it continued after being stopped. This can happen when a process is being debugged.

The exit status is what the process itself provided in a call to exit (or the return value from main, which is defined to be the same thing as calling exit).

But that's not the only way a process can be terminated. In particular, it can be terminated by a signal, which is what will happen if the program segfaults, or divides by zero, or if some other process sends it a kill signal. In those cases, there is no exit status because the program was never able to call exit(). The termination status, then, indicates whether the program called exit(), or, if not, the number of the signal which resulted in termination. There are likely to also be some implementation-specific flags; for example, Linux sets a flag in the termination status if the program terminated by a signal created a core dump.

See main waitpid for the macros you can use to extract this information from the status value returned by waitpid.

Related