Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > E

exit(2)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

exit(), _exit(), _Exit() — terminate a process

SYNOPSIS

#include <stdlib.h>

void exit(int status);

void _Exit(int status);

#include <unistd.h>

void _exit(int status);

Parameters

status

The values of status can be EXIT_SUCCESS or EXIT_FAILURE, as described in <stdlib.h>, or any other value, although only the least significant 8 bits (that is, status & 0377) are available to a waiting parent process.

DESCRIPTION

The exit() function first calls all functions registered by atexit(), in the reverse order of their registration. Each function is called as many times as it was registered. If a function registered by a call to atexit() fails to return, the remaining registered functions are called and the rest of the exit() processing is not completed. exit() terminates the calling process and passes status to the system for inspection (see wait(2)). Returning from main in a C program has the same effect as exit(); the status value is the function value returned by main (this value is undefined if main does not take care to return a value or to call exit() explicitly).

If the calling process is multithreaded, all threads/lightweight process in the process will be terminated.

exit() cannot return to its caller. The result of an exit() call during exit processing is undefined.

The functions exit() and _exit(), are equivalent, except that exit() calls functions registered by atexit() and flushes standard I/O buffers, while _exit() does not.

The function _Exit() is equivalent to _exit().

The functions exit(), _exit(), and _Exit() terminate the calling process with the following consequences. The exact order of these consequences is unspecified.

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

  • All files created by tmpfile() are removed (see tmpfile(3S)).

  • If the parent process of the calling process is executing a wait(), wait3(), or waitpid(), it is notified of the calling process's termination, and the low-order eight bits; that is, bits 0377 of status are made available to it (see wait(2)).

  • If the parent process of the calling process is not executing a wait(), wait3(), or waitpid(), and does not have SIGCLD set to SIG_IGN, the calling process is transformed into a zombie process. A zombie process is a process that only occupies a slot in the process table. It has no other space allocated either in user or kernel space. Time accounting information is recorded for use by times() (see times(2)).

  • The parent process ID is set to the process ID of the initialization process, init (see init(1M)), for all of the calling process's existing child processes and zombie processes. This means the initialization process inherits each of these processes.

  • Threads/LWPs terminated by a call to exit() shall not invoke their cancellation cleanup handlers or their thread specific data destructor functions.

  • 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 (see shmop(2)).

  • For each semaphore for which the calling process has set a semadj value (see semop(2)), that semadj value is added to the value of the specified semaphore.

  • If the process has a process, text, or data lock, an unlock() is performed, see plock(2).

  • An accounting record is written on the accounting file if the system's accounting routine is enabled (see acct(2)).

  • A SIGCHLD signal is sent to the parent process.

  • If the calling 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. The controlling terminal associated with the session is disassociated from the session, allowing it to be acquired by a new controlling process.

  • If the exit of the calling process causes a process group to become orphaned, and if any member of the newly-orphaned process group is stopped, all processes in the newly-orphaned process group are sent SIGHUP and SIGCONT signals.

  • If the current process has any child processes that are being traced, they are sent a SIGKILL signal.

AUTHOR

exit() was developed by HP, AT&T, and the University of California, Berkeley. _exit() and _Exit() were developed by HP.

STANDARDS CONFORMANCE

exit(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

_exit(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

_Exit(): ISO/IEC 9899:1999 (C99), UNIX 03

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.