cause normal program termination to occur


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


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

Note: 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. 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.

These consequences occur on process termination for any reason.


#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 );


POSIX 1003.1

Interrupt handler No
Signal handler Yes
Thread Yes


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()