Reputation: 1
why the exit status in Linux/shell i.e in $? is 128 plus the status number. I have searched but couldn't find proper explanation.
Upvotes: 0
Views: 92
Reputation: 242123
If the exit status is > 127, it's usually the signal number plus 128. The reason is the signal occupies the highest bit in the binary representation of the status.
E.g. 130:
10000010
^ ^
| |
| 2, i.e. SIGINT
killed by a signal
Upvotes: 1
Reputation: 4904
The return value in POSIX compatible systems is only 1 byte = 8 bits = 255 possible values. Unless you find an odd system that supports more than that, you should pick a different set of values.
You can take a look on this question for more details on returned standards code.
Upvotes: 0
Reputation: 25559
Here is the excerpt from bash(1)
:
The return value of a simple command is its exit status, or 128+n if the command is terminated by signal n.
Upvotes: 0