0

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.

3 Answers3

1

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
choroba
  • 216,930
  • 22
  • 195
  • 267
0

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.
wRAR
  • 24,218
  • 4
  • 82
  • 96
0

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.

Community
  • 1
  • 1
developer
  • 4,400
  • 5
  • 37
  • 55