0

A quick explanation and summary:

In HTTP, there are expected codes to represent certain things. For example, 200 means everything is good, whereas 500 means the server is having a problem. Native applications also return status codes. For example, git returns a 0 when everything is ok, but returns a 128 if git isnt set up in the current directory. (Bash returns 127 if git isnt even installed)

Now, the question:

When creating my own application, is there any standard convention that should be used for exit codes?

I know that I should return 0 for when the program exits properly. Is there a standard such as the http standard for exit codes?

Nick Humrich
  • 14,905
  • 8
  • 62
  • 85

1 Answers1

0

EXIT_SUCCESS (i.e. 0) and EXIT_FAILURE (1) are standard, in <stdlib.h>). Read also exit(3) and _exit(2) man pages. Notice that the argument of exit function is bit-or-ed with 0377 octal.

Some BSD systems have more conventions (perhaps in a <sysexits.h> header, see sysexits man page), but GNU/Linux does not follow them a lot.

I suggest sticking to EXIT_FAILURE -on failure- but giving, if possible or relevant, an error message (to stderr or thru syslog(3) ...)

Some commands document their few exit codes.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547