ptg10805159Section 7.3 Process Termination 201
These exit handlers first appeared in the ANSI C Standard in 1989. Systems that predate ANSI
C, such as SVR3 and 4.3BSD, did not provide these exit handlers.ISO C requires that systems support at least 32 exit handlers, but implementations often
support more(see Figure2.15). Thesysconffunction can be used to determine the
maximum number of exit handlers supported by a given platform, as illustrated in Figure2.14.With ISO C and POSIX.1,exitfirst calls the exit handlers and then closes (via
fclose)all open streams. POSIX.1 extends the ISO C standard by specifying that any
exit handlers installed will be cleared if the program calls any of theexecfamily of
functions. Figure7.2 summarizes how a C program is started and the various ways it
can terminate.user
functionsmain
functionCstart-up
routineexit
functionexit handler
...
exit handlerstandardI/O
cleanup
returnreturncallcallexec_exit
or
_Exit_exit
or
_Exit_exit
or
_Exit(does not return)exitexit
(does not return)exit
(does not return)call
return
call
return
call
returnkernel
user processFigure 7.2 How a C program is started and how it terminatesThe only way a program can be executed by the kernel is if one of theexecfunctions is
called. The only way a process can voluntarily terminate is if_exitor_Exitis called,
either explicitly or implicitly (by callingexit). A process can also be involuntarily
terminated by a signal (not shown in Figure7.2).