Exit Codes: Difference between revisions

From Leo's Notes
This page was last edited on 30 December 2021, at 00:48.
mNo edit summary
m Added categories and navbox
Line 335: Line 335:
*Coreutils / Timeout: <nowiki>https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html</nowiki>
*Coreutils / Timeout: <nowiki>https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html</nowiki>
*errno - error numbers used in Linux (<code>errno -ls</code>)
*errno - error numbers used in Linux (<code>errno -ls</code>)
{{Navbox Linux}}
[[Category:Linux]]

Revision as of 00:48, 30 December 2021

Here are some common exit codes that may be returned by a program or script.

Exit Code Description
0 Successful Termination
1 General Error, typical catch-all value
2 Misuse of shell builtins, keywords, or functions
6 No such device or address. Eg. curl on an invalid host.
64-78 BSD exit codes. See section below.
124 Command timed out (coreutils/timeout)
125 Command failure (coreutils/timeout)
126 Command found, but cannot be executed
127 Command not found. Possible path or typo issue.
128 Invalid argument to exit. Eg. exit 1.1 would result in 128.
128+n Fatal error signal n, where n is the signal number as defined in:

https://man7.org/linux/man-pages/man7/signal.7.html

130 Program Interrupted (SIGINT, 128+2), such as termination from Ctrl-C
134 Program Abort (SIGABRT, 128+6)
136 Erroneous Arithmetic Operation (SIGFPE, 128+8), such as division by zero
137 Killed. (SIGKILL, 128+9)
139 Segmentation Fault (SIGSEGV, 11)
160+n The largest signal value is 31. As a result, all values after 128+31 can be interpreted as negative return codes by treating the value as a 1 byte integer.

For example, 255 = -1, 254 = -2, 240 = -16, 225 = -31, and so forth

A simple way to 'convert' it is to just subtract the value from 256.

200-243 Are you working with systemd? See section below.
255 Maximum exit code value. Obtained when the program calls exit -1.
256+ All higher exit codes should be reduced down to the 0-255 range. More information below. You typically either modulo the code by 256 or take the high 8-bit values.

Eg. Code 3809 % 256 results in 225, or code 32512 & 0xff00 >> 8 results in 127.

Parsing high exit code values

At least on Linux (and whatever is reported by Slurm), the exit code that's stored is an 2 byte value which can be parsed as:

Bits Description
high 8 bits The actual exit code
7 bit if a core dump was produced
lower 7 bits signal number that killed the process

For example, the exit code 32512 has an exit code of 127 (command not found).

Systemd exit codes

See the systemd documentation: https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Exit Code Symbolic Name Description
200 EXIT_CHDIR Changing to the requested working directory failed. Issue with WorkingDirectory=
201 EXIT_NICE Failed to set up process scheduling priority (nice level). Issue with Nice=
202 EXIT_FDS Failed to close unwanted file descriptors, or to adjust passed file descriptors.
203 EXIT_EXEC The actual process execution failed (specifically, the execve(2) system call). Most likely this is caused by a missing or non-accessible executable file.
204 EXIT_MEMORY Failed to perform an action due to memory shortage.
205 EXIT_LIMITS Failed to adjust resource limits. Issue with LimitCPU= and related settings
206 EXIT_OOM_ADJUST Failed to adjust the OOM setting. Issue with OOMScoreAdjust=
207 EXIT_SIGNAL_MASK Failed to set process signal mask.
208 EXIT_STDIN Failed to set up standard input. Issue with StandardInput=
209 EXIT_STDOUT Failed to set up standard output. Issue with StandardOutput=
210 EXIT_CHROOT Failed to change root directory (chroot(2)). Issue with RootDirectory=/RootImage=
211 EXIT_IOPRIO Failed to set up IO scheduling priority. Issue with IOSchedulingClass=/IOSchedulingPriority=
212 EXIT_TIMERSLACK Failed to set up timer slack. Issue with TimerSlackNSec=
213 EXIT_SECUREBITS Failed to set process secure bits. Issue with SecureBits=
214 EXIT_SETSCHEDULER Failed to set up CPU scheduling. Issue with CPUSchedulingPolicy=/CPUSchedulingPriority=
215 EXIT_CPUAFFINITY Failed to set up CPU affinity. Issue with CPUAffinity=
216 EXIT_GROUP Failed to determine or change group credentials. Issue with Group=/SupplementaryGroups=
217 EXIT_USER Failed to determine or change user credentials, or to set up user namespacing. Issue with User=/PrivateUsers=
218 EXIT_CAPABILITIES Failed to drop capabilities, or apply ambient capabilities. Issue with CapabilityBoundingSet=/AmbientCapabilities=
219 EXIT_CGROUP Setting up the service control group failed.
220 EXIT_SETSID Failed to create new process session.
221 EXIT_CONFIRM Execution has been cancelled by the user. See the systemd.confirm_spawn= kernel command line setting on kernel-command-line(7) for details.
222 EXIT_STDERR Failed to set up standard error output. Issue with StandardError=
224 EXIT_PAM Failed to set up PAM session. Issue with PAMName=
225 EXIT_NETWORK Failed to set up network namespacing. Issue with PrivateNetwork=
226 EXIT_NAMESPACE Failed to set up mount, UTS, or IPC namespacing. See ReadOnlyPaths=, ProtectHostname=, PrivateIPC=, and related settings.
227 EXIT_NO_NEW_PRIVILEGES Failed to disable new privileges. Issue with NoNewPrivileges=yes
228 EXIT_SECCOMP Failed to apply system call filters. See SystemCallFilter= and related settings
229 EXIT_SELINUX_CONTEXT Determining or changing SELinux context failed. Issue with SELinuxContext=
230 EXIT_PERSONALITY Failed to set up an execution domain (personality). Issue with Personality=
231 EXIT_APPARMOR_PROFILE Failed to prepare changing AppArmor profile. Issue with AppArmorProfile=
232 EXIT_ADDRESS_FAMILIES Failed to restrict address families. Issue with RestrictAddressFamilies=
233 EXIT_RUNTIME_DIRECTORY Setting up runtime directory failed. See RuntimeDirectory= and related settings
235 EXIT_CHOWN Failed to adjust socket ownership. Used for socket units only.
236 EXIT_SMACK_PROCESS_LABEL Failed to set SMACK label. Issue with SmackProcessLabel=
237 EXIT_KEYRING Failed to set up kernel keyring.
238 EXIT_STATE_DIRECTORY Failed to set up unit's state directory. Issue with StateDirectory=
239 EXIT_CACHE_DIRECTORY Failed to set up unit's cache directory. Issue with CacheDirectory=
240 EXIT_LOGS_DIRECTORY Failed to set up unit's logging directory. Issue with LogsDirectory=
241 EXIT_CONFIGURATION_DIRECTORY Failed to set up unit's configuration directory. Issue with ConfigurationDirectory=
242 EXIT_NUMA_POLICY Failed to set up unit's NUMA memory policy. Issue with NUMAPolicy= and NUMAMask=
243 EXIT_CREDENTIALS Failed to set up unit's credentials. Issue with LoadCredential= and SetCredential=

BSD exit codes

Exit Code Symbolic Name Description
64 EX_USAGE Command line usage error
65 EX_DATAERR Data format error
66 EX_NOINPUT Cannot open input
67 EX_NOUSER Addressee unknown
68 EX_NOHOST Host name unknown
69 EX_UNAVAILABLE Service unavailable
70 EX_SOFTWARE internal software error
71 EX_OSERR System error (e.g., can't fork)
72 EX_OSFILE Critical OS file missing
73 EX_CANTCREAT Can't create (user) output file
74 EX_IOERR Input/output error
75 EX_TEMPFAIL Temporary failure; user is invited to retry
76 EX_PROTOCOL Remote error in protocol
77 EX_NOPERM Permission denied
78 EX_CONFIG Configuration error

See Also