Identifying Exit Codes and their meanings

When building on CircleCI (or any other Linux/Unix environment), you may at some point run into a situation where a process has exited causing your build to fail. In this post, we aim to take you through what these codes mean and how they may have manifested.

    If you have experienced exit code 137 and are looking for an immediate answer, please follow this link

 

At the end of most failed builds, you will find the shell will have exited with code 1. This is a catch-all error that simply means something has failed. However, if you search up further in the console, you are likely to find that your process has returned its own status code as it exited.

 

What is an Exit Code?

When a process terminates on a Linux/Unix based system, it may pass a status code back to its parent process (likely your shell). It is common practice to return a 0 if the process has terminated gracefully, and any larger integer would indicate a failure of some condition.

 

The "Advanced Bash-Scripting Guide" has a great reference for reserved status codes you can expect to be standard across most applications.

 

Exit Code Number Meaning Example Comments
1 Catchall for general errors let "var1 = 1/0" Miscellaneous errors, such as "divide by zero" and other impermissible operations
2 Misuse of shell builtins (according to Bash documentation) empty_function() {} Missing keyword or command, or permission problem (and diff return code on a failed binary file comparison).
126 Command invoked cannot execute /dev/null Permission problem or command is not an executable
127 "command not found" illegal_command Possible problem with $PATH or a typo
128 Invalid argument to exit exit 3.14159 exit takes only integer args in the range 0 - 255 (see first footnote)
128+n Fatal error signal "n" kill -9 $PPID of script $? returns 137 (128 + 9)
130 Script terminated by Control-C Ctl-C Control-C is fatal error signal 2, (130 = 128 + 2, see above)
255* Exit status out of range exit -1 exit takes only integer args in the range 0 - 255

 

As we covered earlier, and as you can see in this chart, an exit code of 1 is expected in all cases to represent a generic error.

If you receive an exit code higher than 128, you have received a fatal error signal. Linux also has several standard signals. If you receive an error above 128, you must subtract 128 from that number to identify the signal.

 

Standard Linux Signals

We can see from the man page for Signal the list of standard signals. These signals provide additional insight into why a fatal error had been received.

 

Signal     Value     Action   Comment
──────────────────────────────────────────────────────────────────────
SIGHUP        1       Term    Hangup detected on controlling terminal
                                     or death of controlling process
SIGINT        2       Term    Interrupt from keyboard
SIGQUIT       3       Core    Quit from keyboard
SIGILL        4       Core    Illegal Instruction
SIGABRT       6       Core    Abort signal from abort(3)
SIGFPE        8       Core    Floating-point exception
SIGKILL       9       Term    Kill signal
SIGSEGV      11       Core    Invalid memory reference
SIGPIPE      13       Term    Broken pipe: write to pipe with no
                                     readers; see pipe(7)
SIGALRM      14       Term    Timer signal from alarm(2)
SIGTERM      15       Term    Termination signal
SIGUSR1   30,10,16    Term    User-defined signal 1
SIGUSR2   31,12,17    Term    User-defined signal 2
SIGCHLD   20,17,18    Ign     Child stopped or terminated
SIGCONT   19,18,25    Cont    Continue if stopped
SIGSTOP   17,19,23    Stop    Stop process
SIGTSTP   18,20,24    Stop    Stop typed at terminal
SIGTTIN   21,21,26    Stop    Terminal input for background process
SIGTTOU   22,22,27    Stop    Terminal output for background process

 

So, if you receive the exit code of 137, you must subtract 128 as we stated above to identify which signal you received.

137 - 128 = 9 or SIGKILL

In the scope of CircleCI, 'SGKILL' likely means your build went over its allocated resources, such as RAM, and was ended in response.

 

 

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.