I was thrown off guard today by gdb:

Program exited with code 0146.

gdb prints the return code in octal; looking into why I found: http://comments.gmane.org/gmane.comp.gdb.devel/30363

But that's not a particularly satisfying answer. Some quick googling did not reveal the history, so I was hoping someone on SO might know the back story.

A somewhat related question, how would one even view the return code in octal? Perhaps older machines always printed the return code?

$ printf %o\\n $?

Is pretty awkward :)

  • the $? is the shell's value for return code, and is a decimal digit (or does gdb support your example cmd also?). Don't know why gdb reports it in octal. My solution is to get out the 'ol man ascii to see what the octal values mean. Interesting question, as you do run into octal values from other programs too. Maybe it is discussed in Kernighan and Pike's 'Unix Programming Envioronment'. Good luck.
    – shellter
    Nov 10, 2011 at 14:52
  • The exit status can be larger than a digit, it's actually a byte. Also, man ascii would be of no use to convert octal to decimal. bc would be a better choice.
    – jlliagre
    Nov 10, 2011 at 22:20
  • 2
    The return code is a number, not decimal or octal. The program returns a status (one byte). With wait(3) or its tribe the parent process can find out a lot of information on why the process exited (normally, i.e., voluntarily by calling exit(2); killed by a signal, ...)
    – vonbrand
    Jan 19, 2013 at 23:28

2 Answers 2


The octal representation eases the interpretation of the exit code for small values, which are the most commonly used. Should this number, which is a byte, been printed in decimal, finding which signal interrupted a process would require a little bit of calculation while in octal, they can be read as they are:

  • a process exits with status 5, gdb displays 05 which makes no difference
  • a process exits because it got a SIGINT (Control+C), gdb displays 0202 which is easier to recognize as signal #2 than 130.

Moreover, the exit status might also be a bit mask and in such case, octal (at least when you are used to it which was more common a couple of decades ago than these days) is easier to convert mentally into bits than decimal or even hexadecimal, just like for example chmod still accept an octal number to represent file permissions: 0750 = 111 101 000 = rwx r-x ---.

  • probably the wrong place to ask this, but is there an easy way to tell if a number given by GDB is in octal or decimal?
    – marinara
    Nov 11, 2011 at 7:18
  • 3
    The convention is if it starts with zero (0), it is octal.
    – jlliagre
    Nov 11, 2011 at 7:31

I don't have a copy of this text and just read the short blurb available on google books but. According to the X/Open Portability guide System V Specification Commands & Utilities pg 283(according to google books)

if an application terminates abnormally its exit status is octal 0200 + status, and there is a list of common 'status' values (which are probably also given in octal).

So it is/was a poor mans error message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.