exit() Terminate Process after Cleanup
#include <process.h> Required for declarations only
#include <stdlib.h> Use either process.h or stdlib.h
void exit(status);
int status; Exit status
exit() terminates the calling process and returns the low-byte of
'status' (status & 0xFF) to the waiting parent process, if one
exists. Before terminating, all functions registered with ONEXIT are
called in a "last-in, first-out" order, all stream buffers are
flushed, and all files are closed.
Return: There is no return value; exit() does not return to the
calling process. 'status' is returned to the parent
process. (The parent process is usually the operating
system.)
Notes: exit(0) is automatically called when main() exits.
Typically, the exit status is set to 0 to indicate a
normal exit, and some other value to indicate an error.
This is not required, however.
_exit() has the same function as exit(), but _exit() does
not flush the stream buffers or execute functions
registered with onexit() before terminating.
-------------------------------- Example ---------------------------------
The following statements set the exit status to 1 if more than one
command line argument is passed.
#include <stdio.h> /* for 'printf' */
#include <stdlib.h> /* for 'exit' (also in <process.h>) */
main(argc, argv)
int argc;
char *argv[];
{
if (argc > 2) {
perror("no more than 1 command line parameter allowed\n");
exit(1);
}
/* exit here with a status of 0 */
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster