exit
EXIT(T)             Linux Programmer's Manual             EXIT(T)



NAME
       exit - cause normal program termination

SYNOPSIS
       #include <stdlib.h>

       void exit(int status);

DESCRIPTION
       The  exit() function causes normal program termination and
       the the value of status & 0377 is returned to  the  parent
       (see wait(t)).  All functions registered with atexit() and
       on_exit() are called in the reverse order of their  regis-
       tration,  and  all  open  streams  are flushed and closed.
       Files created by tmpfile() are removed.

       The C standard  specifies  two  defines  EXIT_SUCCESS  and
       EXIT_FAILURE that may be passed to exit() to indicate suc-
       cessful or unsuccessful termination, respectively.

RETURN VALUE
       The exit() function does not return.

CONFORMING TO
       SVID 3, POSIX, BSD 4.3, ISO 9899 (``ANSI C'')

NOTES
       During the exit processing, it  is  possible  to  register
       additional  functions with atexit() and on_exit().  Always
       the last-registered function is removed from the chain  of
       registered  functions,  and invoked.  It is undefined what
       happens  if  during  this  processing  either  exit()   or
       longjmp() is called.

       The  use of EXIT_SUCCESS and EXIT_FAILURE is slightly more
       portable (to non-Unix environments) than  that  of  0  and
       some nonzero value like 1 or -1. In particular, VMS uses a
       different convention.

       BSD has attempted to standardize exit codes - see the file
       <sysexits.h>.

       After  exit(),  the exit status must be transmitted to the
       parent process. There are three cases. If the  parent  has
       set  SA_NOCLDWAIT,  or  has  set  the  SIGCHLD  handler to
       SIG_IGN, the status is discarded. If the parent was  wait-
       ing  on  the  child  it is notified of the exit status. In
       both cases the exiting process dies  immediately.  If  the
       parent  has not indicated that it is not interested in the
       exit status, but is not waiting, the exiting process turns
       into  a "zombie" process (which is nothing but a container
       for the single byte representing the exit status) so  that
       the  parent  can learn the exit status when it later calls
       one of the wait() functions.

       If the implementation supports the  SIGCHLD  signal,  this
       signal  is  sent  to  the  parent.  If  the parent has set
       SA_NOCLDWAIT, it is undefined whether a SIGCHLD signal  is
       sent.

       If  the  process  is  a session leader and its controlling
       terminal the controlling terminal  of  the  session,  then
       each  process in the foreground process group of this con-
       trolling terminal is sent a SIGHUP signal, and the  termi-
       nal  is disassociated from this session, allowing it to be
       acquired by a new controlling process.

       If the exit of the  process  causes  a  process  group  to
       become  orphaned,  and if any member of the newly-orphaned
       process group is stopped, then a SIGHUP signal followed by
       a SIGCONT signal will be sent to each process in this pro-
       cess group.

SEE ALSO
       _exit(t), wait(t), atexit(t), on_exit(t), tmpfile(e)



                            2001-11-17                    EXIT(T)