Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

exit(3) [redhat man page]

EXIT(3) 						     Linux Programmer's Manual							   EXIT(3)

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(2)). All functions registered with atexit() and on_exit() are called in the reverse order of their registration, 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 successful or unsuccessful ter- mination, 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 func- tion 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 waiting 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 sta- tus) 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 fore- ground process group of this controlling terminal is sent a SIGHUP signal, and the terminal 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 process group. SEE ALSO
_exit(2), wait(2), atexit(3), on_exit(3), tmpfile(3) 2001-11-17 EXIT(3)

Check Out this Related Man Page

exit(2) 							System Calls Manual							   exit(2)

NAME
exit, atexit, _exit - Terminates a process LIBRARY
Standard C Library (libc) SYNOPSIS
#include <stdlib.h> int atexit( void (*function) (void)); void exit( int status); #include <unistd.h> void _exit( int status); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: exit(), _exit(), atexit(): XSH4.2 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Indicates the status of the process. Points to a function that is called at normal process termination for cleanup processing. The number of exit handlers that can be specified with the atexit() function is limited by the amount of available virtual memory. DESCRIPTION
The atexit() function registers functions to be called at normal process termination for cleanup processing. The function adds a single exit handler to a list of handlers to be called at process termination. The system calls the functions in reverse order, calling the func- tion at the top of the list first. Any function that is registered more than once will be repeated. The exit() function terminates the calling process after calling the _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 _exit() and exit() functions terminate the calling process and cause the following to occur: All of the file descriptors and directory streams open in the calling process are closed. Since the exit() function terminates the process, any errors encountered during these close operations go unreported. Message catalog descriptors and conversion descriptors opened in the calling process are also closed with no reporting of errors. The parent process ID of all the calling process' existing child processes and zombie processes is reset. The child processes continue executing; however, their parent process ID is set to the process ID of init. The init process thus adopts each of these processes, catches the SIGCHLD signals that 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, that parent process is notified that the calling process is being termi- nated. The low-order 8 bits (that is, bits 0377 or 0xFF) of the status parameter are made available to the parent process. [XSH4.2] This behavior also applies if the parent process is running a wait3() or waitid() function. In addition, this behavior only applies when the parent process of the calling process has neither set its SA_NOCLDWAIT flag nor set SIGCHLD to SIG_IGN. If the parent process is not running a wait() or waitpid() function when the child process terminates, the parent process receives a SIGCHLD signal to notify it that the child process is terminating. The child process is transformed into a zombie process. Once the parent process calls the wait() or waitpid() routine, the child process completes termination and the low-order 8 bits (that is, bits 0377 or 0xFF) of the status parameter are made available to it. [XSH4.2] This behavior also applies to the wait3() and waitid() functions. In addition, this behavior only applies when the parent process has not set its SA_NOCLDWAIT flag or set SIGCHLD to SIG_IGN. The parent process is sent a SIGCHLD signal when a child ter- minates; however, since the default action for this signal is to ignore it, the signal usually is not seen. If the process is a controlling process, the system sends a SIGHUP signal to each process executing in the foreground on the terminal that belongs to the calling process. The terminal is disassociated from the session, allowing it to be acquired by a new controlling process. If the termination of a process causes a process group to become orphaned, and if any member of the newly orphaned process group is stopped, a SIGHUP signal, followed by a SIGCONT signal, is sent to each newly orphaned process. [XSH4.2] If the parent process has set its SA_NOCLDWAIT flag or set SIGCHLD to SIG_IGN, the status is discarded, and the lifetime of the calling process ends imme- diately. [XSH4.2] Each mapped memory object is unmapped. 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 more information about the data structure, see shmget(2).) 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.) [Tru64 UNIX] If the process has a process lock, text lock, or data lock, an unlock is performed. (See the plock() function.) [Tru64 UNIX] An accounting record is written to the accounting file if the system accounting routine is enabled. (The acct() function provides information about enabling accounting routines.) [Tru64 UNIX] Locks set by the fcntl(), flock(), and lockf() functions are removed. [Tru64 UNIX] If a thread calls the _exit() function, the entire process exits and all threads within the process are terminated. NOTES
[XSH4.2] An application should call sysconf() to obtain the value of {ATEXIT_MAX}, the number of handlers that can be registered. There is no way for an application to tell how many functions have already been registered with atexit(). To prematurely terminate atexit handler processing from within a handler, _exit() can be called. It is not recommended to call exit() from within an atexit handler. RETURN VALUES
The exit() function and _exit() function do not return. The atexit() function returns 0 (zero) if successful. The function fails if an application attempts to register more process cleanup func- tions than available virtual memory allows. In this case, the function returns a nonzero value. RELATED INFORMATION
Functions: acct(2), sigaction(2), sigvec(2), wait(2), ldr_atexit(3), times(3) Standards: standards(5) delim off exit(2)
Man Page

Featured Tech Videos