{
    "mode": "man",
    "parameter": "signal-safety",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/signal-safety/7/json",
    "generated": "2026-07-05T13:40:38Z",
    "sections": {
        "NAME": {
            "content": "signal-safety - async-signal-safe functions\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "An  async-signal-safe function is one that can be safely called from within a signal handler.\nMany functions are not async-signal-safe.  In particular, nonreentrant functions  are  gener‐\nally unsafe to call from a signal handler.\n\nThe  kinds of issues that render a function unsafe can be quickly understood when one consid‐\ners the implementation of the stdio library, all of whose  functions  are  not  async-signal-\nsafe.\n\nWhen  performing buffered I/O on a file, the stdio functions must maintain a statically allo‐\ncated data buffer along with associated counters and indexes (or pointers)  that  record  the\namount  of  data and the current position in the buffer.  Suppose that the main program is in\nthe middle of a call to a stdio function such as printf(3) where the  buffer  and  associated\nvariables  have  been partially updated.  If, at that moment, the program is interrupted by a\nsignal handler that also calls printf(3), then the second call to printf(3) will  operate  on\ninconsistent data, with unpredictable results.\n\nTo avoid problems with unsafe functions, there are two possible choices:\n\n1. Ensure  that  (a)  the  signal handler calls only async-signal-safe functions, and (b) the\nsignal handler itself is reentrant with respect to global variables in the main program.\n\n2. Block signal delivery in the main program when calling functions that are unsafe or  oper‐\nating on global data that is also accessed by the signal handler.\n\nGenerally,  the second choice is difficult in programs of any complexity, so the first choice\nis taken.\n\nPOSIX.1 specifies a set of functions that an implementation must make async-signal-safe.  (An\nimplementation  may provide safe implementations of additional functions, but this is not re‐\nquired by the standard and other implementations may not provide the same guarantees.)\n\nIn general, a function is async-signal-safe either because it is reentrant or because  it  is\natomic  with  respect  to  signals (i.e., its execution can't be interrupted by a signal han‐\ndler).\n\nThe set of functions required to be async-signal-safe by POSIX.1 is shown  in  the  following\ntable.   The  functions  not  otherwise  noted  were  required  to  be  async-signal-safe  in\nPOSIX.1-2001; the table details changes in the subsequent standards.\n",
            "subsections": [
                {
                    "name": "Function               Notes",
                    "content": "abort(3)               Added in POSIX.1-2001 TC1\naccept(2)\naccess(2)\naioerror(3)\naioreturn(3)\naiosuspend(3)         See notes below\nalarm(2)\nbind(2)\ncfgetispeed(3)\ncfgetospeed(3)\ncfsetispeed(3)\ncfsetospeed(3)\nchdir(2)\nchmod(2)\nchown(2)\nclockgettime(2)\nclose(2)\n\nconnect(2)\ncreat(2)\ndup(2)\ndup2(2)\nexecl(3)               Added in POSIX.1-2008; see notes below\nexecle(3)              See notes below\nexecv(3)               Added in POSIX.1-2008\nexecve(2)\nexit(2)\nExit(2)\nfaccessat(2)           Added in POSIX.1-2008\nfchdir(2)              Added in POSIX.1-2008 TC1\nfchmod(2)\nfchmodat(2)            Added in POSIX.1-2008\nfchown(2)\nfchownat(2)            Added in POSIX.1-2008\nfcntl(2)\nfdatasync(2)\nfexecve(3)             Added in POSIX.1-2008\nffs(3)                 Added in POSIX.1-2008 TC2\nfork(2)                See notes below\nfstat(2)\nfstatat(2)             Added in POSIX.1-2008\nfsync(2)\nftruncate(2)\nfutimens(3)            Added in POSIX.1-2008\ngetegid(2)\ngeteuid(2)\ngetgid(2)\ngetgroups(2)\ngetpeername(2)\ngetpgrp(2)\ngetpid(2)\ngetppid(2)\ngetsockname(2)\ngetsockopt(2)\ngetuid(2)\nhtonl(3)               Added in POSIX.1-2008 TC2\nhtons(3)               Added in POSIX.1-2008 TC2\nkill(2)\nlink(2)\nlinkat(2)              Added in POSIX.1-2008\nlisten(2)\nlongjmp(3)             Added in POSIX.1-2008 TC2; see notes below\nlseek(2)\nlstat(2)\nmemccpy(3)             Added in POSIX.1-2008 TC2\nmemchr(3)              Added in POSIX.1-2008 TC2\nmemcmp(3)              Added in POSIX.1-2008 TC2\nmemcpy(3)              Added in POSIX.1-2008 TC2\nmemmove(3)             Added in POSIX.1-2008 TC2\nmemset(3)              Added in POSIX.1-2008 TC2\nmkdir(2)\nmkdirat(2)             Added in POSIX.1-2008\nmkfifo(3)\nmkfifoat(3)            Added in POSIX.1-2008\nmknod(2)               Added in POSIX.1-2008\nmknodat(2)             Added in POSIX.1-2008\nntohl(3)               Added in POSIX.1-2008 TC2\nntohs(3)               Added in POSIX.1-2008 TC2\nopen(2)\nopenat(2)              Added in POSIX.1-2008\npause(2)\npipe(2)\npoll(2)\n\nposixtraceevent(3)\npselect(2)\npthreadkill(3)        Added in POSIX.1-2008 TC1\npthreadself(3)        Added in POSIX.1-2008 TC1\npthreadsigmask(3)     Added in POSIX.1-2008 TC1\nraise(3)\nread(2)\nreadlink(2)\nreadlinkat(2)          Added in POSIX.1-2008\nrecv(2)\nrecvfrom(2)\nrecvmsg(2)\nrename(2)\nrenameat(2)            Added in POSIX.1-2008\nrmdir(2)\nselect(2)\nsempost(3)\nsend(2)\nsendmsg(2)\nsendto(2)\nsetgid(2)\nsetpgid(2)\nsetsid(2)\nsetsockopt(2)\nsetuid(2)\nshutdown(2)\nsigaction(2)\nsigaddset(3)\nsigdelset(3)\nsigemptyset(3)\nsigfillset(3)\nsigismember(3)\nsiglongjmp(3)          Added in POSIX.1-2008 TC2; see notes below\nsignal(2)\nsigpause(3)\nsigpending(2)\nsigprocmask(2)\nsigqueue(2)\nsigset(3)\nsigsuspend(2)\nsleep(3)\nsockatmark(3)          Added in POSIX.1-2001 TC2\nsocket(2)\nsocketpair(2)\nstat(2)\nstpcpy(3)              Added in POSIX.1-2008 TC2\nstpncpy(3)             Added in POSIX.1-2008 TC2\nstrcat(3)              Added in POSIX.1-2008 TC2\nstrchr(3)              Added in POSIX.1-2008 TC2\nstrcmp(3)              Added in POSIX.1-2008 TC2\nstrcpy(3)              Added in POSIX.1-2008 TC2\nstrcspn(3)             Added in POSIX.1-2008 TC2\nstrlen(3)              Added in POSIX.1-2008 TC2\nstrncat(3)             Added in POSIX.1-2008 TC2\nstrncmp(3)             Added in POSIX.1-2008 TC2\nstrncpy(3)             Added in POSIX.1-2008 TC2\nstrnlen(3)             Added in POSIX.1-2008 TC2\nstrpbrk(3)             Added in POSIX.1-2008 TC2\nstrrchr(3)             Added in POSIX.1-2008 TC2\nstrspn(3)              Added in POSIX.1-2008 TC2\nstrstr(3)              Added in POSIX.1-2008 TC2\nstrtokr(3)            Added in POSIX.1-2008 TC2\nsymlink(2)\nsymlinkat(2)           Added in POSIX.1-2008\ntcdrain(3)\n\ntcflow(3)\ntcflush(3)\ntcgetattr(3)\ntcgetpgrp(3)\ntcsendbreak(3)\ntcsetattr(3)\ntcsetpgrp(3)\ntime(2)\ntimergetoverrun(2)\ntimergettime(2)\ntimersettime(2)\ntimes(2)\numask(2)\nuname(2)\nunlink(2)\nunlinkat(2)            Added in POSIX.1-2008\nutime(2)\nutimensat(2)           Added in POSIX.1-2008\nutimes(2)              Added in POSIX.1-2008\nwait(2)\nwaitpid(2)\nwcpcpy(3)              Added in POSIX.1-2008 TC2\nwcpncpy(3)             Added in POSIX.1-2008 TC2\nwcscat(3)              Added in POSIX.1-2008 TC2\nwcschr(3)              Added in POSIX.1-2008 TC2\nwcscmp(3)              Added in POSIX.1-2008 TC2\nwcscpy(3)              Added in POSIX.1-2008 TC2\nwcscspn(3)             Added in POSIX.1-2008 TC2\nwcslen(3)              Added in POSIX.1-2008 TC2\nwcsncat(3)             Added in POSIX.1-2008 TC2\nwcsncmp(3)             Added in POSIX.1-2008 TC2\nwcsncpy(3)             Added in POSIX.1-2008 TC2\nwcsnlen(3)             Added in POSIX.1-2008 TC2\nwcspbrk(3)             Added in POSIX.1-2008 TC2\nwcsrchr(3)             Added in POSIX.1-2008 TC2\nwcsspn(3)              Added in POSIX.1-2008 TC2\nwcsstr(3)              Added in POSIX.1-2008 TC2\nwcstok(3)              Added in POSIX.1-2008 TC2\nwmemchr(3)             Added in POSIX.1-2008 TC2\nwmemcmp(3)             Added in POSIX.1-2008 TC2\nwmemcpy(3)             Added in POSIX.1-2008 TC2\nwmemmove(3)            Added in POSIX.1-2008 TC2\nwmemset(3)             Added in POSIX.1-2008 TC2\nwrite(2)\n\nNotes:\n\n*  POSIX.1-2001 and POSIX.1-2001 TC2 required the functions  fpathconf(3),  pathconf(3),  and\nsysconf(3) to be async-signal-safe, but this requirement was removed in POSIX.1-2008.\n\n*  If a signal handler interrupts the execution of an unsafe function, and the handler termi‐\nnates via a call to longjmp(3) or siglongjmp(3) and the program subsequently calls an  un‐\nsafe function, then the behavior of the program is undefined.\n\n*  POSIX.1-2001  TC1 clarified that if an application calls fork(2) from a signal handler and\nany of the fork handlers registered by pthreadatfork(3) calls  a  function  that  is  not\nasync-signal-safe, the behavior is undefined.  A future revision of the standard is likely\nto remove fork(2) from the list of async-signal-safe functions.\n\n*  Asynchronous signal handlers that call functions which are cancellation  points  and  nest\nover  regions  of  deferred  cancellation may trigger cancellation whose behavior is as if\nasynchronous cancellation had occurred and may cause application state to become inconsis‐\ntent.\n"
                },
                {
                    "name": "errno",
                    "content": "Fetching and setting the value of errno is async-signal-safe provided that the signal handler\nsaves errno on entry and restores its value before returning.\n"
                },
                {
                    "name": "Deviations in the GNU C library",
                    "content": "The following known deviations from the standard occur in the GNU C library:\n\n*  Before glibc 2.24, execl(3) and execle(3) employed realloc(3) internally and  were  conse‐\nquently not async-signal-safe.  This was fixed in glibc 2.24.\n\n*  The  glibc  implementation  of  aiosuspend(3)  is  not  async-signal-safe because it uses\npthreadmutexlock(3) internally.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "sigaction(2), signal(7), standards(7)\n",
            "subsections": []
        },
        "COLOPHON": {
            "content": "This page is part of release 5.10 of the Linux  man-pages  project.   A  description  of  the\nproject,  information about reporting bugs, and the latest version of this page, can be found\nat https://www.kernel.org/doc/man-pages/.\n\n\n\nLinux                                        2020-12-21                             SIGNAL-SAFETY(7)",
            "subsections": []
        }
    },
    "summary": "signal-safety - async-signal-safe functions",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "sigaction",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/sigaction/2/json"
        },
        {
            "name": "signal",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/signal/7/json"
        },
        {
            "name": "standards",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/standards/7/json"
        }
    ]
}