Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

acct(2)

sigaction(2)

times(2)

wait(2)

sigset(2)

EXIT(2)                              SysV                              EXIT(2)



NAME
     exit, _exit - terminate process

SYNOPSIS
     void _exit(status)
     int status;

     #include <stdlib.h>

     int atexit(void (*function)(void))

     void exit(status)
     int status;

DESCRIPTION
     The atexit function registers functions to be called at normal process
     termination for cleanup processing.

     The exit function terminates the calling process after calling the
     Standard I/O Library _cleanup function to flush any buffered output.
     Then it calls any functions registered previously for the process by the
     atexit function, in the reverse order to that in which they were
     registered. In addition, the exit function flushes all open output
     streams, closes all open streams, and removes all files created by the
     tmpfile function.  Finally, it calls the _exit function, which completes
     process termination and does not return.

     The arguments are defined as follows:

     status    Indicates the status of the process.

     function  Points to a function that is called at normal process
               termination for cleanup processing. A push-down stack of
               functions is kept, such that the last function registered is
               the first function called.  Any function which is registered
               more than once will be repeated.

     The _exit and _exit functions terminate the calling process and cause the
     following to occur:

     +    All of the file descriptors, directory streams, and message catalog
          descriptors open in the calling process are closed.

     +    Terminating a process by exiting does not terminate its child
          processes.  Instead, the parent process ID of all of the calling
          process child processes and zombie child processes is set to the
          process ID of init.  The init process thus inherits each of these
          processes, catches the SIGCHLD signals they generate, and calls the
          wait function for each of them.

     +    If the parent process of the calling process is running a wait or
          waitpid function, it is notified of the termination of the calling
          process and the low-order 8 bits (that is, bits 0377) of the status
          argument are made available to it.

     +    The parent process ID of all of the calling processes' existing
          child processes and zombie processes is set to 1.  This means the
          initialization process (see intro(2)) inherits each of these
          processes.

     +    If the parent process is not running a wait or waitpid function when
          the child process terminates, it may do so later on, and the child's
          status will be returned to it at that time.  Meanwhile, the child
          process is transformed into a zombie process, and its parent process
          is sent a SIGCHLD signal to notify it of the termination of a child
          process.

          A process remains a zombie until its parent issues one of the wait
          functions. At this time, the zombie is laid to rest, and its process
          table entry is released.

     +    The parent process is sent a SIGCHLD signal when a child terminates.

          If an exiting child's parent is ignoring the SIGCHLD signal, the
          child's parent process ID is changed to that of the initialization
          process, init, which will catch the SIGCHLD signal and call the wait
          function.

     +    If the process is a controlling process, a SIGHUP signal is sent to
          each process in the foreground process group of the controlling
          terminal belonging to the calling process.  The controlling terminal
          is disassociated from the session, allowing it to be acquired by a
          new controlling process.

     +    If the exit of a process causes a process group to become orphaned,
          and if any member of the newly orphaned process group is stopped,
          then a SIGHUP signal is sent to each newly orphaned process.

     +    Each attached shared memory segment is detached and the value of
          shm_nattach in the data structure associated with its shared memory
          identifier is decremented by 1.

     +    For each semaphore for which the calling process has set a semadj
          value, that semadj value is added to the semval of the specified
          semaphore. (The semop function provides information about semaphore
          operations.)

     +    If the process has a process lock, text lock, or data lock, an
          unlock is performed. (See the plock function.)

     +    An accounting record is written on the accounting file if the system
          accounting routine is enabled. (The acct function provides
          information about enabling accounting routines.)

DIAGNOSTICS
     The exit function and _exit function do not return.  The atexit function
     returns 0 (zero) if successful, and a nonzero value if there has been an
     attempt to register more exit functions than can be held in the atexit
     array.

SEE ALSO
     acct(2), sigaction(2), times(2), wait(2), sigset(2)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026