Why the exit status of a program is important
To date, we've always used exit(EXIT_FAILURE)
when a problem has been detected,
or exit(EXIT_SUCCESS) when all has gone well.
Why?
The operating system is able to use the exit status of a program to
determine if it was successful.
Consider the following program which exits with the integer status
provided as a command-line argument:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int status = EXIT_SUCCESS; // DEFAULT STATUS IS SUCCESS (=0)
if(argc > 1) {
status = atoi(argv[1]);
}
printf("exiting(%i)\n", status);
exit(status);
}
|
CITS2002 Systems Programming, Lecture 9, p7, 19th August 2024.
|