_exit

cause normal program termination to occur

Synopsis:

#include <stdlib.h>
void _exit( int status );

Description:

The _exit() function causes normal program termination to occur.

The functions registered by the atexit() or onexit() function aren't called.
  1. All open file descriptors and directory streams in the calling process are closed.
  2. If the parent process of the calling process is executing a wait() or waitpid(), it is notified of the calling process's termination and the low order 8 bits of status are made available to it.
  3. If the parent process of the calling process isn't executing a wait() or waitpid() function, the exit status code is saved, for return to the parent process whenever the parent process executes an appropriate subsequent wait() or waitpid().
  4. Termination of a process doesn't directly terminate its children. The sending of a SIGHUP signal, as described below, indirectly terminates children in some circumstances. Children of a terminated process are assigned a new parent process ID, corresponding to an implementation-defined system process.
  5. If the implementation supports the SIGCHLD signal, a SIGCHLD signal is sent to the parent process.
  6. If the process is a controlling process, the SIGHUP signal is sent to each process in the foreground process group of the controlling terminal belonging to the calling process.
  7. If the process is a controlling process, the controlling terminal associated with the session is disassociated from the session, allowing it to be acquired by a new controlling process.
  8. If the implementation supports job control, and 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 is sent to each process in the newly-orphaned process group.

These consequences occur on process termination for any reason.

Returns:

The _exit() function doesn't return to its caller.

See also:

abort(), atexit(), _bgetcmd() , close() , exec... functions, exit(), getcmd(), getenv(), main(), onexit(), putenv() , sigaction(), signal() , spawn... functions, system() , wait(), waitpid()

Examples:

#include <stdio.h>
#include <stdlib.h>

void main( int argc, char *argv[] )
  {
    FILE *fp;

    if( argc <= 1 ) {
      fprintf( stderr, "Missing argument\n" );
      exit( EXIT_FAILURE );
    }

    fp = fopen( argv[1], "r" );
    if( fp == NULL ) {
      fprintf( stderr, "Unable to open '%s'\n", argv[1] );
      _exit( EXIT_FAILURE );
    }
    fclose( fp );
    _exit( EXIT_SUCCESS );
  }

Classification:

POSIX 1003.1

Systems:

All (except Netware, DOS/PM)