What is conventional return values for applications in Windows and GNU/Linux respectivly. 0 means success. But what should be used on user-requested abort. When I abort on Windows, it returns 3, but this value is not in the list of system error codes if it is not an ERROR_PATH_NOT_FOUND. GNU binutils uses 1. From a user perspective, returning GetLastError or errno would be good since they are documented, but is these only seems to cover lower level status codes. I am looking for a value that represents "Application terminated unsuccessfully"
The reason I wounder is that I want to
exit(errcode)
from a signal handler that catches some Access Violation/SIGSEGV (i.e programming errors) after printing a message about where it occured. Then the error code should be destiguishable from user input errors.
The exit status of a process in computer programming is a small number passed from a child process (or callee) to a parent process (or caller) when it has finished executing a specific procedure or delegated task. In DOS, this may be referred to as an errorlevel.
The simple explanation for an exit code is that the executable program is programmed to return a whole number that shows whether it was successfully executed. In general, zero is usually the signal for successful execution, and numbers from 1-255 represent various negative outcomes or problems.
Exit Status Out of Range: 255. Depending on our shell, exit code 255 might mean that the returned exit code is outside of the 0-255 range.
# By convention, an 'exit 0' indicates success, #+ while a non-zero exit value means an error or anomalous condition. # See the "Exit Codes With Special Meanings" appendix. $? is especially useful for testing the result of a command in a script (see Example 16-35 and Example 16-20).
This might help, http://tldp.org/LDP/abs/html/exitcodes.html those are the standard exit code. The rest of them I think are program dependant. basically you need to verify the documentation of the specific software you are looking for. As @devnull said, any exit code that is not zero implies an unsuccessful termination
This is only few conventions about exit codes. Let's see what some manuals say:
The GNU C Library Reference Manual
There are conventions for what sorts of status values certain programs should return. The most common convention is simply 0 for success and 1 for failure ...
A general convention reserves status values 128 and up for special purposes
- Some non-POSIX systems use different conventions for exit status values
- For greater portability, you can use the macros EXIT_SUCCESS and EXIT_FAILURE for the conventional status value for success and failure.
ISO/IEC 9899:2011 (C11 standard)
If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If the value of status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.
That means if you want (and for most cases that's enough) just indicate success or failure you definitely should use EXIT_SUCCESS and EXIT_FAILURE. If you want indicate other errors, you should reinvent your own exit statuses. For example:
#define HEX_FILE_CREATE 2
#define HEX_FILE_CREATE 3
...
There is additional tips on what and how you should return:
- Warning: Don’t try to use the number of errors as the exit status. This is actually not very useful; a parent process would generally not care how many errors occurred. Worse than that, it does not work, because the status value is truncated to eight bits. Thus, if the program tried to report 256 errors, the parent would receive a report of 0 errors—that is, success
- For the same reason, it does not work to use the value of errno as the exit status—these can exceed 255
Conclusion:
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