Value returned by a simple order (128 + n)

4

Good evening to the stack community. I am studying man bash, and in "shell grammar" I have a doubt, which, in principle, is not strictly programming, so if it is considered out of place (I hope you tell me if it is), edit to delete it .

According to man bash:

  

The return value of a simple command is its output state, or 128 + n if the command has ended due to the signal n.

I understand that the signals referred to are those described in the man signal, such as SIGKILL (9), which kills a process, or SIGILL (4), referring to an illegal instruction. However, well read the man signal,

  

Linux supports real-time signals as originally defined in POSIX.4 real-time extensions (now included in POSIX 1003.1-2001). Linux supports 32 signals in real time, numbered from 32 (SIGRTMIN) to 63 (SIGRTMAX). (Programs should always reference real-time signals using the SIGRTMIN + n notation, since the range of real-time signal numbers varies between Unix systems.)

(The signals from 1 to 31 would be the standard signals).

Is there, then, the signal 128? What does it mean and where is it defined?

[email protected]:~/scripts$ uname -r && bash --version 4.16.0-686-pae GNU bash, versión 4.4.23(1)-release (i686-pc-linux-gnu)

Thanks in advance.

Edit: Assuming that 128 + n is a real-time signal (the same is too much to assume for me), the value returned by a simple command, when the order ends with the signal n, should not be 32 + n (SIGRTMIN + n) ?

I said: thank you very much, and if the question exceeds the scope of stackoverflow, let me know, I'll remove the question.

    
asked by GuardabosqueS 21.12.2018 в 00:04
source

2 answers

1

A signal is different from an exit status. Now, what of the number 128 I think is (without references) by 256 (of the available output states) between 2. That would be the shell where it runs and a subshell from where the signal less than or equal to 128 is issued.

For example.

$ export senial
$ for senial in {1..15}
for> do
for> bash -c 'bash -c "kill -$senial \$\$"; echo "$?"' 2> /dev/null
for> done
129
130
0
132
133
134
135
136
137
138
139
140
141
142
143

And it shows me your exit status as the exit status 128 + the signal .

If you include the range {1..123} in the for, you see that the output state is according to the formula described, but until the signal 32. Then, in the range of [32-64], the output is of 0, then, the output is a general error, that is equal to 1.

    
answered by 21.12.2018 / 22:59
source
1

Perhaps by writing, @mrc_es, you understood that it did not differentiate between the output state and the signal.
In case anyone who arrives here helps you:
The exit status "determines the destination of the result of a program or process, by default it is the screen and the result of a program or process, by default it is the screen and the result is displayed in the terminal console, although it can be redirected to a file ". Or to other "places", I add, like the bottomless sack / dev / null ...
I have not found a better definition of signal than "an asynchronous notification or event that one process sends to another".
Yes I have been able to read that there are up to 256 signals available in GNU / Linux, and, in fact, Appendix E of the Advanced Bash-Scripting Guide ( link ) (Codes with special meanings) manifests:

  

exit codes 1 - 2, 126 - 165, and 255 [1] have special meanings, and should there be avoided for user-specified exit parameters.
  [...]   
  There has been an attempt to systematize exit status numbers (see / usr / include / s andsexits.h), but this is intended for C and C ++ programmers. A similar standard for scripting might be appropriate.
  [...]
  [1] Out of range exit values can result in unexpected exit codes.
  An exit value greater than 255 returns an exit code module 256. For example, exit 3809 gives an exit code of 225 (3809% 256 = 225).

Again from my absolute ignorance, and without a source I can cite, I dare to venture that, at the kernel level, any signal is sent as a single bit, which would allow a maximum of 256 signals (2 raised to 8). Another thing is that there is a definite meaning for each of them: the man signal is illustrative about it.
Thanks again, @mrc_es.
PS: I have dared to answer my own question, being supported in little more than my own logic, because in commentaries all this does not enter, by limit of characters.

    
answered by 28.12.2018 в 00:08