I just need the general meaning of it to work out a crash. Theirs nothing about it anywhere else that I could find.
The purpose of the exit() function is to terminate the execution of a program. The “return 0”(or EXIT_SUCCESS) implies that the code has executed successfully without any error. Exit codes other than “0”(or EXIT_FAILURE) indicate the presence of an error in the code.
An exit code is a system response that reports success, an error, or another condition that provides a clue about what caused an unexpected result from your command or script. Yet, you might never know about the code, because an exit code doesn't reveal itself unless someone asks it to do so.
An exit code, or sometimes known as a return code, is the code returned to a parent process by an executable. On POSIX systems the standard exit code is 0 for success and any number from 1 to 255 for anything else. Exit codes can be interpreted by machine scripts to adapt in the event of successes of failures.
Under Linux and most other Unix variants, the signal number 11 indicates a segmentation fault, as remarked by Kerrek SB.
Programs dying due to POSIX signal SIGABRT
exit with an error code of 6
and the highest bit set.
SIGABRT
is caused by calling abort()
which might be due to an assert
ion failing.
If the highest bit isn't set, it's an application-specific error code. You can type echo $?
into your shell to see what error code the application right before exited with.
Regarding the C main
function, there is no general standard of exit codes. It is a convention that a program returns 0 if it has been done successful and everything else otherwise. But even this is rather a thumb rule.
A specific application may have specific return codes which hopefully are documented somewhere.
After digging a little bit deeper I found exit
(cppreference.com). I consider this because exit()
is the other possibility to leave an application and I'm quite sure that the passed exit value is processed the same way like the return value of main()
.
It mentions EXIT_SUCCESS
and EXIT_FAILURE
:
control is returned to the host environment. If exit_code is zero or EXIT_SUCCESS, an implementation-defined status, indicating successful termination is returned. If exit_code is EXIT_FAILURE, an implementation-defined status, indicating unsuccessful termination is returned. In other cases implementation-defined status value is returned.
On this site, there are also links to the respective C standards.
A similar statement can be found in the Linux man page of exit:
The C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE, that may be passed to exit() to indicate successful or unsuccessful termination, respectively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With