Junior — Middle
Can you list the possible process exit codes in Linux and their meanings?
sobes.tech AI
Answer from AI
In Linux, the process exit code is an integer that indicates the result of the process. Usually, code 0 means successful completion, and any non-zero value indicates an error or a special condition.
Main values:
- 0 — successful completion.
- 1-255 — various errors defined by the application.
- If the process was terminated by a signal, the exit code is usually 128 + the signal number.
For example, if a process was killed by the SIGKILL signal (number 9), the exit code would be 137 (128 + 9).
There are also standard error codes, for example:
- 2 — error in command line usage (e.g., invalid arguments).
- 126 — command found but cannot be executed.
- 127 — command not found.
To get the process exit code in a shell, you can use the variable $?.
Example:
./my_program
echo $?