linux - [Solved-5 Solutions] Are there any standard exit status codes in Linux ? - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
Are there any standard exit status codes in Linux ?
Linux - Solution 1:
The shell only stores an 8-bit return code, but sets the high bit if the process was abnormally terminated.
If you're seeing anything other than this, then the program probably has a SIGSEGV signal handler which then calls exit normally, so it isn't actually getting killed by the signal.
Linux - Solution 2:
Part 1: Advanced Bash Scripting
- 1: Catchall for general errors
- 2: Misuse of shell builtins (according to Bash documentation)
- 126: Command invoked cannot execute
- 127: "command not found"
- 128: Invalid argument to exit
- 128+n: Fatal error signal "n"
- 255: Exit status out of range
Part 2: sysexits.h
The ABSG references sysexits.h.
On Linux:
Linux - Solution 3:
- 1 Catchall for general errors
- 2 Misuse of shell builtins (according to Bash documentation)
- 126 Command invoked cannot execute
- 127 "command not found"
- 128 Invalid argument to exit
- 128+n Fatal error signal "n"
- 130 Script terminated by Control-C
- 255 Exit status out of range
- This is for bash. However, for other applications, there are different exit codes.
Linux - Solution 4:
From the OpenBSD:
- According to style(9), it is not good practice to call exit(3) with arbi- trary values to indicate a failure condition when ending a program.
- In- stead, the pre-defined exit codes from sysexits should be used, so the caller of the process can get a rough estimation about the failure class without looking up the source code
Linux - Solution 5:
- There are no standard exit codes, aside from 0 meaning success. Non-zero doesn't necessarily mean failure either.
- stdlib.h does define EXIT_FAILURE as 1 and EXIT_SUCCESS as 0, but that's about it.
- The 11 on segfault is interesting, as 11 is the signal number that the kernel uses to kill the process in the event of a segfault.
- There is likely some mechanism, either in the kernel or in the shell, that translates that into the exit code