Internet
Fact-checked

At EasyTechJunkie, we're committed to delivering accurate, trustworthy information. Our expert-authored content is rigorously fact-checked and sourced from credible authorities. Discover how we uphold the highest standards in providing you with reliable knowledge.

Learn more...

What Is the Exit Status?

Eugene P.
Eugene P.

The exit status of a program, also called the return code, is a number that a program passes to the operating system, script or other process that originally executed it once the program has finished running. There are no real rules for what the numbers used as an exit status mean, although a value of zero traditionally means the program exited normally, and any non-zero value means the program terminated unexpectedly. By assigning a number to the exit status, the original program or process that called the code can tell whether the program successfully performed the tasks needed or other actions need to be taken.

Nearly all computer languages and many scripting languages have some mechanism or function in place that can return an exit status. There are situations in which a program can intentionally terminate in the middle of running, using a specific error code to indicate that something is wrong, such as a missing data file or a lack of computer memory. Programs that do not explicitly define an exit status code will return a zero to the calling program unless the operating system or language interpreter terminates the program because of errors.

Man holding computer
Man holding computer

The exit status also can be used to communicate with a script or another process by passing specific values back that indicate what action should be taken next. One example would be a script that is designed to keep a program running despite possible times when the program might exit for maintenance. This scheme would operate with the script executing the program and then waiting for it to exit. The programmers could arrange it so the program returns one number to mean it is permanently exiting and should not be restarted, and another number could instruct the script to wait for a period of time and then restart the program; still a third value could indicate the program encountered an error and needs attention from a programmer.

The use of an exit status code for communications is convenient in certain situations because of the security and other limitations that some programs have under different operating systems. There are many instances in which it is impossible for a program to communicate with its calling process or another program running parallel on the same system. In these situations, the options for communications between programs would be limited to complex schemes involving shared memory, network socket connections or writing files. By using an exit status, simple information can be passed in a very basic way that does not require a custom framework to be developed.

Discuss this Article

Post your comments
Login:
Forgot password?
Register:
    • Man holding computer
      Man holding computer