Linux How to get error description by error number

In linux (in particular, I have Ubuntu 14), if any program completes the error, can I get a numerical error code using the $? variable $?

 $ ./failing_app $ echo $? 

However, the number itself does not tell me how to get the name and description of the error?

$ man errno has a list of errors, but it only gives names, not numeric values.

I searched google and the results are rather strange: for example. I have a Rust toy in which I am trying to access an array element outside the bounds. Panic program and $? is equal to 101 , however, as they say, it corresponds to the Network unreachable error, which makes no sense.

0
source share
3 answers

The program exit status ( $? In the shell) is not related to C errno .

In a C program, usually the exit state is from argument to exit or the return value of main . The convention is that 0 means successful exit (or true for the shell), and other values ​​are a failure (ir false).

However, if the program died from receiving a signal, the shell sets $? at 128 plus the signal number. For example, with a segmentation error ( SIGSEGV , which is 11), $? will be 139.

To list the signal numbers, run kill -l .

+1
source

There is no single central governing body. Each program assigns its own semantics to error codes. Good ones have documentation on the manual page; for example, see, for example, grep and xargs pages from GNU.

exit (3) The Linux manual page also states that "BSD attempted to standardize exit codes." The BSD sysexits (3) man page is a really recommended read, the bus, as indicated, is slightly larger than the push for a limited number of script errors.

The kernel has a much more detailed and well-documented set of possible errors and their causes, but this is obviously limited by system calls and does not affect application-level errors at all. For Linux, see the errno (3) man page.

The Bash Advanced Scripting Guide has a section on general conventions; http://tldp.org/LDP/abs/html/exitcodes.html#EXITCODESREF - but, like ABS in general, this is an unholy mixture of standards, conventions, the author’s personal opinion, guesses and lies, (None of the exit codes in the table "reserved," although he already says so, and the text that refers to the table underlines this incorrect fact.)

+1
source

This link contains a list of errors with numbers. Hope this is what you are looking for. http://www.thegeekstuff.com/2010/10/linux-error-codes/

In addition, on my system, I see that in the /usr/include/asm-generic/errno-base.h file there are error definitions as well as error numbers. It will be better than a link.

0
source

All Articles