Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


exit(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ATTRIBUTES |STANDARDS |HISTORY |NOTES |SEE ALSO |COLOPHON

exit(3)                  Library Functions Manualexit(3)

NAME        top

       exit - cause normal process termination

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <stdlib.h>[[noreturn]] void exit(intstatus);

DESCRIPTION        top

       Theexit() function causes normal process termination and the       least significant byte ofstatus (i.e.,status & 0xFF) is returned       to the parent (seewait(2)).       All functions registered withatexit(3) andon_exit(3) are called,       in the reverse order of their registration.  (It is possible for       one of these functions to useatexit(3) oron_exit(3) to register       an additional function to be executed during exit processing; the       new registration is added to the front of the list of functions       that remain to be called.)  If one of these functions does not       return (e.g., it calls_exit(2), or kills itself with a signal),       then none of the remaining functions is called, and further exit       processing (in particular, flushing ofstdio(3) streams) is       abandoned.  If a function has been registered multiple times usingatexit(3) oron_exit(3), then it is called as many times as it was       registered.       All openstdio(3) streams are flushed and closed.  Files created       bytmpfile(3) are removed.       The C standard specifies two constants,EXIT_SUCCESSandEXIT_FAILURE, that may be passed toexit() to indicate successful       or unsuccessful termination, respectively.

RETURN VALUE        top

       Theexit() function does not return.

ATTRIBUTES        top

       For an explanation of the terms used in this section, seeattributes(7).       ┌──────────────────────────┬───────────────┬─────────────────────┐       │InterfaceAttributeValue│       ├──────────────────────────┼───────────────┼─────────────────────┤       │exit()                   │ Thread safety │ MT-Unsafe race:exit │       └──────────────────────────┴───────────────┴─────────────────────┘       Theexit() function uses a global variable that is not protected,       so it is not thread-safe.

STANDARDS        top

       C11, POSIX.1-2008.

HISTORY        top

       C89, POSIX.1-2001, SVr4, 4.3BSD.

NOTES        top

       The behavior is undefined if one of the functions registered usingatexit(3) andon_exit(3) calls eitherexit() orlongjmp(3).  Note       that a call toexecve(2) removes registrations created usingatexit(3) andon_exit(3).       The use ofEXIT_SUCCESSandEXIT_FAILUREis slightly more portable       (to non-UNIX environments) than the use of 0 and some nonzero       value like 1 or -1.  In particular, VMS uses a different       convention.       BSD has attempted to standardize exit codes (which some C       libraries such as the GNU C library have also adopted); see the       file<sysexits.h>.       Afterexit(), the exit status must be transmitted to the parent       process.  There are three cases:       •  If the parent has setSA_NOCLDWAIT, or has set theSIGCHLD          handler toSIG_IGN, the status is discarded and the child dies          immediately.       •  If the parent was waiting on the child, it is notified of the          exit status and the child dies immediately.       •  Otherwise, the child becomes a "zombie" process: most of the          process resources are recycled, but a slot containing minimal          information about the child process (termination status,          resource usage statistics) is retained in process table.  This          allows the parent to subsequently usewaitpid(2) (or similar)          to learn the termination status of the child; at that point the          zombie process slot is released.       If the implementation supports theSIGCHLDsignal, this signal is       sent to the parent.  If the parent has setSA_NOCLDWAIT, it is       undefined whether aSIGCHLDsignal is sent.Signals sent to other processes       If the exiting process is a session leader and its controlling       terminal is the controlling terminal of the session, then each       process in the foreground process group of this controlling       terminal is sent aSIGHUPsignal, 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 aSIGHUPsignal followed by aSIGCONTsignal will be       sent to each process in this process group.  Seesetpgid(2) for an       explanation of orphaned process groups.       Except in the above cases, where the signalled processes may be       children of the terminating process, termination of a process doesnot in general cause a signal to be sent to children of that       process.  However, a process can use theprctl(2)PR_SET_PDEATHSIG       operation to arrange that it receives a signal if its parent       terminates.

SEE ALSO        top

_exit(2),get_robust_list(2),setpgid(2),wait(2),atexit(3),on_exit(3),tmpfile(3)

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-05-17exit(3)

Pages that refer to this page:man(1)_exit(2)kill(2)vfork(2)wait(2)abort(3)assert(3)assert_perror(3)atexit(3)err(3)error(3)EXIT_SUCCESS(3const)on_exit(3)pthread_create(3)pthread_detach(3)pthread_exit(3)sd_bus_set_exit_on_disconnect(3)setjmp(3)stdin(3)stdio(3)sysexits.h(3head)tmpfile(3)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp