signal-safety(7)
๐ NAME ๐
signal-safety โ async-signal-safe functions.
Bestie, this one comes to you straight outta the Miscellaneous Information Manual, and it's genuinely one of the most important lil pages in section 7, no cap. ๐ซถ
๐ธ DESCRIPTION ๐ธ
okay so. An async-signal-safe function is one that can be safely called from within a signal handler. That's the whole vibe. Many functions are not async-signal-safe. In particular, nonreentrant functions are generally unsafe to call from a signal handler. ๐
The kinds of issues that render a function unsafe can be quickly understood when one considers the implementation of the stdio library, all of whose functions are not async-signal-safe. And yes, that means every single one. ๐
When performing buffered I/O on a file, the stdio functions must maintain a statically allocated data buffer along with associated counters and indexes (or pointers) that record the amount of data and the current position in the buffer. So picture this: the main program is in the middle of a call to a stdio function such as printf(3) where the buffer and associated variables have been partially updated. If, at that moment, the program is interrupted by a signal handler that also calls printf(3), then the second call to printf(3) will operate on inconsistent data, with unpredictable results. ๐งจ Not the slay. Not it.
To avoid problems with unsafe functions, there are two possible choices:
- (a) Ensure that (1) the signal handler calls only async-signal-safe functions, and (2) the signal handler itself is reentrant with respect to global variables in the main program.
- (b) Block signal delivery in the main program when calling functions that are unsafe or operating on global data that is also accessed by the signal handler.
Generally, the second choice is difficult in programs of any complexity, so the first choice is taken. Periodt. ๐
POSIX.1 specifies a set of functions that an implementation must make async-signal-safe. (An implementation may provide safe implementations of additional functions, but this is not required by the standard and other implementations may not provide the same guarantees.) So like, a platform could be extra, but don't count on it. ๐ โโ๏ธ
In general, a function is async-signal-safe either because it is reentrant or because it is atomic with respect to signals (i.e., its execution can't be interrupted by a signal handler). ๐
The set of functions required to be async-signal-safe by POSIX.1 is shown in the following table. The functions not otherwise noted were required to be async-signal-safe in POSIX.1-2001; the table details changes in the subsequent standards. So the plain ones are day-one icons, and the annotated ones got added later. ๐
๐ the list ๐
abort(3)โ Added in POSIX.1-2001 TC1accept(2)access(2)aio_error(3)aio_return(3)aio_suspend(3)โ See notes belowalarm(2)bind(2)cfgetispeed(3)cfgetospeed(3)cfsetispeed(3)cfsetospeed(3)chdir(2)chmod(2)chown(2)clock_gettime(2)close(2)connect(2)creat(2)dup(2)dup2(2)execl(3)โ Added in POSIX.1-2008; see notes belowexecle(3)โ See notes belowexecv(3)โ Added in POSIX.1-2008execve(2)_exit(3)_Exit(3)faccessat(2)โ Added in POSIX.1-2008fchdir(2)โ Added in POSIX.1-2008 TC1fchmod(2)fchmodat(2)โ Added in POSIX.1-2008fchown(2)fchownat(2)โ Added in POSIX.1-2008fcntl(2)fdatasync(2)fexecve(3)โ Added in POSIX.1-2008ffs(3)โ Added in POSIX.1-2008 TC2_Fork(3)fstat(2)fstatat(2)โ Added in POSIX.1-2008fsync(2)ftruncate(2)futimens(3)โ Added in POSIX.1-2008getegid(2)geteuid(2)getgid(2)getgroups(2)getpeername(2)getpgrp(2)getpid(2)getppid(2)getsockname(2)getsockopt(2)getuid(2)htonl(3)โ Added in POSIX.1-2008 TC2htons(3)โ Added in POSIX.1-2008 TC2kill(2)link(2)linkat(2)โ Added in POSIX.1-2008listen(2)longjmp(3)โ Added in POSIX.1-2008 TC2; see notes belowlseek(2)lstat(2)memccpy(3)โ Added in POSIX.1-2008 TC2memchr(3)โ Added in POSIX.1-2008 TC2memcmp(3)โ Added in POSIX.1-2008 TC2memcpy(3)โ Added in POSIX.1-2008 TC2memmove(3)โ Added in POSIX.1-2008 TC2memset(3)โ Added in POSIX.1-2008 TC2mkdir(2)mkdirat(2)โ Added in POSIX.1-2008mkfifo(3)mkfifoat(3)โ Added in POSIX.1-2008mknod(2)โ Added in POSIX.1-2008mknodat(2)โ Added in POSIX.1-2008ntohl(3)โ Added in POSIX.1-2008 TC2ntohs(3)โ Added in POSIX.1-2008 TC2open(2)openat(2)โ Added in POSIX.1-2008pause(2)pipe(2)poll(2)posix_trace_event(3)pselect(2)pthread_kill(3)โ Added in POSIX.1-2008 TC1pthread_self(3)โ Added in POSIX.1-2008 TC1pthread_sigmask(3)โ Added in POSIX.1-2008 TC1raise(3)read(2)readlink(2)readlinkat(2)โ Added in POSIX.1-2008recv(2)recvfrom(2)recvmsg(2)rename(2)renameat(2)โ Added in POSIX.1-2008rmdir(2)select(2)sem_post(3)send(2)sendmsg(2)sendto(2)setgid(2)setpgid(2)setsid(2)setsockopt(2)setuid(2)shutdown(2)sigaction(2)sigaddset(3)sigdelset(3)sigemptyset(3)sigfillset(3)sigismember(3)siglongjmp(3)โ Added in POSIX.1-2008 TC2; see notes belowsignal(2)sigpause(3)sigpending(2)sigprocmask(2)sigqueue(2)sigset(3)sigsuspend(2)sleep(3)sockatmark(3)โ Added in POSIX.1-2001 TC2socket(2)socketpair(2)stat(2)stpcpy(3)โ Added in POSIX.1-2008 TC2stpncpy(3)โ Added in POSIX.1-2008 TC2strcat(3)โ Added in POSIX.1-2008 TC2strchr(3)โ Added in POSIX.1-2008 TC2strcmp(3)โ Added in POSIX.1-2008 TC2strcpy(3)โ Added in POSIX.1-2008 TC2strcspn(3)โ Added in POSIX.1-2008 TC2strlen(3)โ Added in POSIX.1-2008 TC2strncat(3)โ Added in POSIX.1-2008 TC2strncmp(3)โ Added in POSIX.1-2008 TC2strncpy(3)โ Added in POSIX.1-2008 TC2strnlen(3)โ Added in POSIX.1-2008 TC2strpbrk(3)โ Added in POSIX.1-2008 TC2strrchr(3)โ Added in POSIX.1-2008 TC2strspn(3)โ Added in POSIX.1-2008 TC2strstr(3)โ Added in POSIX.1-2008 TC2strtok_r(3)โ Added in POSIX.1-2008 TC2symlink(2)symlinkat(2)โ Added in POSIX.1-2008tcdrain(3)tcflow(3)tcflush(3)tcgetattr(3)tcgetpgrp(3)tcsendbreak(3)tcsetattr(3)tcsetpgrp(3)time(2)timer_getoverrun(2)timer_gettime(2)timer_settime(2)times(2)umask(2)uname(2)unlink(2)unlinkat(2)โ Added in POSIX.1-2008utime(2)utimensat(2)โ Added in POSIX.1-2008utimes(2)โ Added in POSIX.1-2008wait(2)waitpid(2)wcpcpy(3)โ Added in POSIX.1-2008 TC2wcpncpy(3)โ Added in POSIX.1-2008 TC2wcscat(3)โ Added in POSIX.1-2008 TC2wcschr(3)โ Added in POSIX.1-2008 TC2wcscmp(3)โ Added in POSIX.1-2008 TC2wcscpy(3)โ Added in POSIX.1-2008 TC2wcscspn(3)โ Added in POSIX.1-2008 TC2wcslen(3)โ Added in POSIX.1-2008 TC2wcsncat(3)โ Added in POSIX.1-2008 TC2wcsncmp(3)โ Added in POSIX.1-2008 TC2wcsncpy(3)โ Added in POSIX.1-2008 TC2wcsnlen(3)โ Added in POSIX.1-2008 TC2wcspbrk(3)โ Added in POSIX.1-2008 TC2wcsrchr(3)โ Added in POSIX.1-2008 TC2wcsspn(3)โ Added in POSIX.1-2008 TC2wcsstr(3)โ Added in POSIX.1-2008 TC2wcstok(3)โ Added in POSIX.1-2008 TC2wmemchr(3)โ Added in POSIX.1-2008 TC2wmemcmp(3)โ Added in POSIX.1-2008 TC2wmemcpy(3)โ Added in POSIX.1-2008 TC2wmemmove(3)โ Added in POSIX.1-2008 TC2wmemset(3)โ Added in POSIX.1-2008 TC2write(2)
Notes: ๐
- POSIX.1-2001 and POSIX.1-2001 TC2 required the functions
fpathconf(3),pathconf(3), andsysconf(3)to be async-signal-safe, but this requirement was removed in POSIX.1-2008. - If a signal handler interrupts the execution of an unsafe function, and the handler terminates via a call to
longjmp(3)orsiglongjmp(3)and the program subsequently calls an unsafe function, then the behavior of the program is undefined. Like, undefined undefined. Don't do it. ๐ญ - Asynchronous signal handlers that call functions which are cancelation points and nest over regions of deferred cancelation may trigger cancelation whose behavior is as if asynchronous cancelation had occurred and may cause application state to become inconsistent.
๐ errno ๐
Fetching and setting the value of errno is async-signal-safe provided that the signal handler saves errno on entry and restores its value before returning. Save it, restore it, that's the whole ritual. ๐
๐ง Deviations in the GNU C library ๐ง
The following known deviations from the standard occur in the GNU C library:
- Before glibc 2.24,
execl(3)andexecle(3)employedrealloc(3)internally and were consequently not async-signal-safe. This was fixed in glibc 2.24. glow-up achieved โจ - The glibc implementation of
aio_suspend(3)is not async-signal-safe because it usespthread_mutex_lock(3)internally. ๐ฉ
๐ SEE ALSO ๐
sigaction(2), signal(7), standards(7)
and that's the whole page, bestie ๐ this one shipped in Linux man-pages 6.20, dated 2026-06-05 โ go keep your signal handlers reentrant, mwah ๐๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2016, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms