Exit Program

We can exit normal execution of a program by calling exit or abort. Normal execution ends with an exit code of zero. We call exit(0); and program exits with a success. However program can also return unexpectedly. These are the situations when program encounters erroneous situations like memory allocation failure or critical calculation errors like divide by zero etc. Programmers prefer calling exit with a proper error code. Windows/Linux has standard error numbers (errno) defined for every categories of errors. Programmers can even return the same error code received from the last system call. This error code will be saved in the process exit status code. Exit using abort is a different process. It raise a SIGABORT to the process and process exits as the default signal action taken by operating system. Process status will be updated accordingly. Parent process can obtain these status code and can decide if process completed successfully or aborted.

abort

void abort(void);

Causes an abnormal program termination. Raises the SIGABRT signal and an unsuccessful termination status is returned to the environment. Whether or not open streams are closed is implementation-defined. No return is possible.

exit

void exit(int status);

Causes the program to terminate normally. First the functions registered by atexit are called, then all open streams are flushed and closed, and all temporary files opened with tmpfile are removed. The value of status is returned to the environment. If status is EXIT_SUCCESS, then this signifies a successful termination. If status is EXIT_FAILURE, then this signifies an unsuccessful termination. All other values are implementation-defined. No return is possible.

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

argv environ getenv, system(), atexit, raise signal, abort exit, Libraries, static linking, dynamic linking methods,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan