# info > signal-safety

---
type: CommandReference
command: signal-safety
mode: man
section: 7
source: man-pages
---

## Quick Reference

- `write(2)` — async-signal-safe write to a file descriptor
- `read(2)` — async-signal-safe read from a file descriptor
- `open(2)` — async-signal-safe open a file
- `close(2)` — async-signal-safe close a file descriptor
- `fork(2)` — async-signal-safe create a child process (with caveats)
- `execve(2)` — async-signal-safe execute a program
- `sigaction(2)` — async-signal-safe examine and change signal action
- `_exit(2)` — async-signal-safe terminate the calling process

## Name

signal-safety — async-signal-safe functions

## Synopsis

Async-signal-safe functions can be safely called from within a signal handler. Many functions (e.g., stdio functions) are not safe because they use static buffers. Two choices: (1) use only async-signal-safe functions and ensure reentrancy, or (2) block signals. Choice 1 is typical.

## Options

The following functions are required to be async-signal-safe by POSIX.1. Notes indicate changes in subsequent standards or known deviations.

- `[abort(3)](https://man7.org/linux/man-pages/man3/abort.3.html)` — Added in POSIX.1-2001 TC1
- `[accept(2)](https://man7.org/linux/man-pages/man2/accept.2.html)`
- `[access(2)](https://man7.org/linux/man-pages/man2/access.2.html)`
- `[aio_error(3)](https://man7.org/linux/man-pages/man3/aio_error.3.html)`
- `[aio_return(3)](https://man7.org/linux/man-pages/man3/aio_return.3.html)`
- `[aio_suspend(3)](https://man7.org/linux/man-pages/man3/aio_suspend.3.html)` — glibc implementation uses `pthread_mutex_lock(3)` internally, so not async-signal-safe in glibc
- `[alarm(2)](https://man7.org/linux/man-pages/man2/alarm.2.html)`
- `[bind(2)](https://man7.org/linux/man-pages/man2/bind.2.html)`
- `[cfgetispeed(3)](https://man7.org/linux/man-pages/man3/cfgetispeed.3.html)`
- `[cfgetospeed(3)](https://man7.org/linux/man-pages/man3/cfgetospeed.3.html)`
- `[cfsetispeed(3)](https://man7.org/linux/man-pages/man3/cfsetispeed.3.html)`
- `[cfsetospeed(3)](https://man7.org/linux/man-pages/man3/cfsetospeed.3.html)`
- `[chdir(2)](https://man7.org/linux/man-pages/man2/chdir.2.html)`
- `[chmod(2)](https://man7.org/linux/man-pages/man2/chmod.2.html)`
- `[chown(2)](https://man7.org/linux/man-pages/man2/chown.2.html)`
- `[clock_gettime(2)](https://man7.org/linux/man-pages/man2/clock_gettime.2.html)`
- `[close(2)](https://man7.org/linux/man-pages/man2/close.2.html)`
- `[connect(2)](https://man7.org/linux/man-pages/man2/connect.2.html)`
- `[creat(2)](https://man7.org/linux/man-pages/man2/creat.2.html)`
- `[dup(2)](https://man7.org/linux/man-pages/man2/dup.2.html)`
- `[dup2(2)](https://man7.org/linux/man-pages/man2/dup2.2.html)`
- `[execl(3)](https://man7.org/linux/man-pages/man3/execl.3.html)` — Added in POSIX.1-2008; before glibc 2.24 used `realloc(3)` internally, not async-signal-safe; fixed in glibc 2.24
- `[execle(3)](https://man7.org/linux/man-pages/man3/execle.3.html)` — Same note as execl
- `[execv(3)](https://man7.org/linux/man-pages/man3/execv.3.html)` — Added in POSIX.1-2008
- `[execve(2)](https://man7.org/linux/man-pages/man2/execve.2.html)`
- `[_exit(2)](https://man7.org/linux/man-pages/man2/_exit.2.html)`
- `[_Exit(2)](https://man7.org/linux/man-pages/man2/_Exit.2.html)`
- `[faccessat(2)](https://man7.org/linux/man-pages/man2/faccessat.2.html)` — Added in POSIX.1-2008
- `[fchdir(2)](https://man7.org/linux/man-pages/man2/fchdir.2.html)` — Added in POSIX.1-2008 TC1
- `[fchmod(2)](https://man7.org/linux/man-pages/man2/fchmod.2.html)`
- `[fchmodat(2)](https://man7.org/linux/man-pages/man2/fchmodat.2.html)` — Added in POSIX.1-2008
- `[fchown(2)](https://man7.org/linux/man-pages/man2/fchown.2.html)`
- `[fchownat(2)](https://man7.org/linux/man-pages/man2/fchownat.2.html)` — Added in POSIX.1-2008
- `[fcntl(2)](https://man7.org/linux/man-pages/man2/fcntl.2.html)`
- `[fdatasync(2)](https://man7.org/linux/man-pages/man2/fdatasync.2.html)`
- `[fexecve(3)](https://man7.org/linux/man-pages/man3/fexecve.3.html)` — Added in POSIX.1-2008
- `[ffs(3)](https://man7.org/linux/man-pages/man3/ffs.3.html)` — Added in POSIX.1-2008 TC2
- `[fork(2)](https://man7.org/linux/man-pages/man2/fork.2.html)` — See notes: if called from a signal handler and any `pthread_atfork(3)` handler calls a non-async-signal-safe function, behavior is undefined. Future revision likely to remove `fork(2)` from the list.
- `[fstat(2)](https://man7.org/linux/man-pages/man2/fstat.2.html)`
- `[fstatat(2)](https://man7.org/linux/man-pages/man2/fstatat.2.html)` — Added in POSIX.1-2008
- `[fsync(2)](https://man7.org/linux/man-pages/man2/fsync.2.html)`
- `[ftruncate(2)](https://man7.org/linux/man-pages/man2/ftruncate.2.html)`
- `[futimens(3)](https://man7.org/linux/man-pages/man3/futimens.3.html)` — Added in POSIX.1-2008
- `[getegid(2)](https://man7.org/linux/man-pages/man2/getegid.2.html)`
- `[geteuid(2)](https://man7.org/linux/man-pages/man2/geteuid.2.html)`
- `[getgid(2)](https://man7.org/linux/man-pages/man2/getgid.2.html)`
- `[getgroups(2)](https://man7.org/linux/man-pages/man2/getgroups.2.html)`
- `[getpeername(2)](https://man7.org/linux/man-pages/man2/getpeername.2.html)`
- `[getpgrp(2)](https://man7.org/linux/man-pages/man2/getpgrp.2.html)`
- `[getpid(2)](https://man7.org/linux/man-pages/man2/getpid.2.html)`
- `[getppid(2)](https://man7.org/linux/man-pages/man2/getppid.2.html)`
- `[getsockname(2)](https://man7.org/linux/man-pages/man2/getsockname.2.html)`
- `[getsockopt(2)](https://man7.org/linux/man-pages/man2/getsockopt.2.html)`
- `[getuid(2)](https://man7.org/linux/man-pages/man2/getuid.2.html)`
- `[htonl(3)](https://man7.org/linux/man-pages/man3/htonl.3.html)` — Added in POSIX.1-2008 TC2
- `[htons(3)](https://man7.org/linux/man-pages/man3/htons.3.html)` — Added in POSIX.1-2008 TC2
- `[kill(2)](https://man7.org/linux/man-pages/man2/kill.2.html)`
- `[link(2)](https://man7.org/linux/man-pages/man2/link.2.html)`
- `[linkat(2)](https://man7.org/linux/man-pages/man2/linkat.2.html)` — Added in POSIX.1-2008
- `[listen(2)](https://man7.org/linux/man-pages/man2/listen.2.html)`
- `[longjmp(3)](https://man7.org/linux/man-pages/man3/longjmp.3.html)` — Added in POSIX.1-2008 TC2; if a signal handler interrupts an unsafe function and terminates via `longjmp(3)` or `siglongjmp(3)`, subsequent calls to unsafe functions result in undefined behavior
- `[lseek(2)](https://man7.org/linux/man-pages/man2/lseek.2.html)`
- `[lstat(2)](https://man7.org/linux/man-pages/man2/lstat.2.html)`
- `[memccpy(3)](https://man7.org/linux/man-pages/man3/memccpy.3.html)` — Added in POSIX.1-2008 TC2
- `[memchr(3)](https://man7.org/linux/man-pages/man3/memchr.3.html)` — Added in POSIX.1-2008 TC2
- `[memcmp(3)](https://man7.org/linux/man-pages/man3/memcmp.3.html)` — Added in POSIX.1-2008 TC2
- `[memcpy(3)](https://man7.org/linux/man-pages/man3/memcpy.3.html)` — Added in POSIX.1-2008 TC2
- `[memmove(3)](https://man7.org/linux/man-pages/man3/memmove.3.html)` — Added in POSIX.1-2008 TC2
- `[memset(3)](https://man7.org/linux/man-pages/man3/memset.3.html)` — Added in POSIX.1-2008 TC2
- `[mkdir(2)](https://man7.org/linux/man-pages/man2/mkdir.2.html)`
- `[mkdirat(2)](https://man7.org/linux/man-pages/man2/mkdirat.2.html)` — Added in POSIX.1-2008
- `[mkfifo(3)](https://man7.org/linux/man-pages/man3/mkfifo.3.html)`
- `[mkfifoat(3)](https://man7.org/linux/man-pages/man3/mkfifoat.3.html)` — Added in POSIX.1-2008
- `[mknod(2)](https://man7.org/linux/man-pages/man2/mknod.2.html)` — Added in POSIX.1-2008
- `[mknodat(2)](https://man7.org/linux/man-pages/man2/mknodat.2.html)` — Added in POSIX.1-2008
- `[ntohl(3)](https://man7.org/linux/man-pages/man3/ntohl.3.html)` — Added in POSIX.1-2008 TC2
- `[ntohs(3)](https://man7.org/linux/man-pages/man3/ntohs.3.html)` — Added in POSIX.1-2008 TC2
- `[open(2)](https://man7.org/linux/man-pages/man2/open.2.html)`
- `[openat(2)](https://man7.org/linux/man-pages/man2/openat.2.html)` — Added in POSIX.1-2008
- `[pause(2)](https://man7.org/linux/man-pages/man2/pause.2.html)`
- `[pipe(2)](https://man7.org/linux/man-pages/man2/pipe.2.html)`
- `[poll(2)](https://man7.org/linux/man-pages/man2/poll.2.html)`
- `[posix_trace_event(3)](https://man7.org/linux/man-pages/man3/posix_trace_event.3.html)`
- `[pselect(2)](https://man7.org/linux/man-pages/man2/pselect.2.html)`
- `[pthread_kill(3)](https://man7.org/linux/man-pages/man3/pthread_kill.3.html)` — Added in POSIX.1-2008 TC1
- `[pthread_self(3)](https://man7.org/linux/man-pages/man3/pthread_self.3.html)` — Added in POSIX.1-2008 TC1
- `[pthread_sigmask(3)](https://man7.org/linux/man-pages/man3/pthread_sigmask.3.html)` — Added in POSIX.1-2008 TC1
- `[raise(3)](https://man7.org/linux/man-pages/man3/raise.3.html)`
- `[read(2)](https://man7.org/linux/man-pages/man2/read.2.html)`
- `[readlink(2)](https://man7.org/linux/man-pages/man2/readlink.2.html)`
- `[readlinkat(2)](https://man7.org/linux/man-pages/man2/readlinkat.2.html)` — Added in POSIX.1-2008
- `[recv(2)](https://man7.org/linux/man-pages/man2/recv.2.html)`
- `[recvfrom(2)](https://man7.org/linux/man-pages/man2/recvfrom.2.html)`
- `[recvmsg(2)](https://man7.org/linux/man-pages/man2/recvmsg.2.html)`
- `[rename(2)](https://man7.org/linux/man-pages/man2/rename.2.html)`
- `[renameat(2)](https://man7.org/linux/man-pages/man2/renameat.2.html)` — Added in POSIX.1-2008
- `[rmdir(2)](https://man7.org/linux/man-pages/man2/rmdir.2.html)`
- `[select(2)](https://man7.org/linux/man-pages/man2/select.2.html)`
- `[sem_post(3)](https://man7.org/linux/man-pages/man3/sem_post.3.html)`
- `[send(2)](https://man7.org/linux/man-pages/man2/send.2.html)`
- `[sendmsg(2)](https://man7.org/linux/man-pages/man2/sendmsg.2.html)`
- `[sendto(2)](https://man7.org/linux/man-pages/man2/sendto.2.html)`
- `[setgid(2)](https://man7.org/linux/man-pages/man2/setgid.2.html)`
- `[setpgid(2)](https://man7.org/linux/man-pages/man2/setpgid.2.html)`
- `[setsid(2)](https://man7.org/linux/man-pages/man2/setsid.2.html)`
- `[setsockopt(2)](https://man7.org/linux/man-pages/man2/setsockopt.2.html)`
- `[setuid(2)](https://man7.org/linux/man-pages/man2/setuid.2.html)`
- `[shutdown(2)](https://man7.org/linux/man-pages/man2/shutdown.2.html)`
- `[sigaction(2)](https://man7.org/linux/man-pages/man2/sigaction.2.html)`
- `[sigaddset(3)](https://man7.org/linux/man-pages/man3/sigaddset.3.html)`
- `[sigdelset(3)](https://man7.org/linux/man-pages/man3/sigdelset.3.html)`
- `[sigemptyset(3)](https://man7.org/linux/man-pages/man3/sigemptyset.3.html)`
- `[sigfillset(3)](https://man7.org/linux/man-pages/man3/sigfillset.3.html)`
- `[sigismember(3)](https://man7.org/linux/man-pages/man3/sigismember.3.html)`
- `[siglongjmp(3)](https://man7.org/linux/man-pages/man3/siglongjmp.3.html)` — Added in POSIX.1-2008 TC2; same note as longjmp
- `[signal(2)](https://man7.org/linux/man-pages/man2/signal.2.html)`
- `[sigpause(3)](https://man7.org/linux/man-pages/man3/sigpause.3.html)`
- `[sigpending(2)](https://man7.org/linux/man-pages/man2/sigpending.2.html)`
- `[sigprocmask(2)](https://man7.org/linux/man-pages/man2/sigprocmask.2.html)`
- `[sigqueue(2)](https://man7.org/linux/man-pages/man2/sigqueue.2.html)`
- `[sigset(3)](https://man7.org/linux/man-pages/man3/sigset.3.html)`
- `[sigsuspend(2)](https://man7.org/linux/man-pages/man2/sigsuspend.2.html)`
- `[sleep(3)](https://man7.org/linux/man-pages/man3/sleep.3.html)`
- `[sockatmark(3)](https://man7.org/linux/man-pages/man3/sockatmark.3.html)` — Added in POSIX.1-2001 TC2
- `[socket(2)](https://man7.org/linux/man-pages/man2/socket.2.html)`
- `[socketpair(2)](https://man7.org/linux/man-pages/man2/socketpair.2.html)`
- `[stat(2)](https://man7.org/linux/man-pages/man2/stat.2.html)`
- `[stpcpy(3)](https://man7.org/linux/man-pages/man3/stpcpy.3.html)` — Added in POSIX.1-2008 TC2
- `[stpncpy(3)](https://man7.org/linux/man-pages/man3/stpncpy.3.html)` — Added in POSIX.1-2008 TC2
- `[strcat(3)](https://man7.org/linux/man-pages/man3/strcat.3.html)` — Added in POSIX.1-2008 TC2
- `[strchr(3)](https://man7.org/linux/man-pages/man3/strchr.3.html)` — Added in POSIX.1-2008 TC2
- `[strcmp(3)](https://man7.org/linux/man-pages/man3/strcmp.3.html)` — Added in POSIX.1-2008 TC2
- `[strcpy(3)](https://man7.org/linux/man-pages/man3/strcpy.3.html)` — Added in POSIX.1-2008 TC2
- `[strcspn(3)](https://man7.org/linux/man-pages/man3/strcspn.3.html)` — Added in POSIX.1-2008 TC2
- `[strlen(3)](https://man7.org/linux/man-pages/man3/strlen.3.html)` — Added in POSIX.1-2008 TC2
- `[strncat(3)](https://man7.org/linux/man-pages/man3/strncat.3.html)` — Added in POSIX.1-2008 TC2
- `[strncmp(3)](https://man7.org/linux/man-pages/man3/strncmp.3.html)` — Added in POSIX.1-2008 TC2
- `[strncpy(3)](https://man7.org/linux/man-pages/man3/strncpy.3.html)` — Added in POSIX.1-2008 TC2
- `[strnlen(3)](https://man7.org/linux/man-pages/man3/strnlen.3.html)` — Added in POSIX.1-2008 TC2
- `[strpbrk(3)](https://man7.org/linux/man-pages/man3/strpbrk.3.html)` — Added in POSIX.1-2008 TC2
- `[strrchr(3)](https://man7.org/linux/man-pages/man3/strrchr.3.html)` — Added in POSIX.1-2008 TC2
- `[strspn(3)](https://man7.org/linux/man-pages/man3/strspn.3.html)` — Added in POSIX.1-2008 TC2
- `[strstr(3)](https://man7.org/linux/man-pages/man3/strstr.3.html)` — Added in POSIX.1-2008 TC2
- `[strtok_r(3)](https://man7.org/linux/man-pages/man3/strtok_r.3.html)` — Added in POSIX.1-2008 TC2
- `[symlink(2)](https://man7.org/linux/man-pages/man2/symlink.2.html)`
- `[symlinkat(2)](https://man7.org/linux/man-pages/man2/symlinkat.2.html)` — Added in POSIX.1-2008
- `[tcdrain(3)](https://man7.org/linux/man-pages/man3/tcdrain.3.html)`
- `[tcflow(3)](https://man7.org/linux/man-pages/man3/tcflow.3.html)`
- `[tcflush(3)](https://man7.org/linux/man-pages/man3/tcflush.3.html)`
- `[tcgetattr(3)](https://man7.org/linux/man-pages/man3/tcgetattr.3.html)`
- `[tcgetpgrp(3)](https://man7.org/linux/man-pages/man3/tcgetpgrp.3.html)`
- `[tcsendbreak(3)](https://man7.org/linux/man-pages/man3/tcsendbreak.3.html)`
- `[tcsetattr(3)](https://man7.org/linux/man-pages/man3/tcsetattr.3.html)`
- `[tcsetpgrp(3)](https://man7.org/linux/man-pages/man3/tcsetpgrp.3.html)`
- `[time(2)](https://man7.org/linux/man-pages/man2/time.2.html)`
- `[timer_getoverrun(2)](https://man7.org/linux/man-pages/man2/timer_getoverrun.2.html)`
- `[timer_gettime(2)](https://man7.org/linux/man-pages/man2/timer_gettime.2.html)`
- `[timer_settime(2)](https://man7.org/linux/man-pages/man2/timer_settime.2.html)`
- `[times(2)](https://man7.org/linux/man-pages/man2/times.2.html)`
- `[umask(2)](https://man7.org/linux/man-pages/man2/umask.2.html)`
- `[uname(2)](https://man7.org/linux/man-pages/man2/uname.2.html)`
- `[unlink(2)](https://man7.org/linux/man-pages/man2/unlink.2.html)`
- `[unlinkat(2)](https://man7.org/linux/man-pages/man2/unlinkat.2.html)` — Added in POSIX.1-2008
- `[utime(2)](https://man7.org/linux/man-pages/man2/utime.2.html)`
- `[utimensat(2)](https://man7.org/linux/man-pages/man2/utimensat.2.html)` — Added in POSIX.1-2008
- `[utimes(2)](https://man7.org/linux/man-pages/man2/utimes.2.html)` — Added in POSIX.1-2008
- `[wait(2)](https://man7.org/linux/man-pages/man2/wait.2.html)`
- `[waitpid(2)](https://man7.org/linux/man-pages/man2/waitpid.2.html)`
- `[wcpcpy(3)](https://man7.org/linux/man-pages/man3/wcpcpy.3.html)` — Added in POSIX.1-2008 TC2
- `[wcpncpy(3)](https://man7.org/linux/man-pages/man3/wcpncpy.3.html)` — Added in POSIX.1-2008 TC2
- `[wcscat(3)](https://man7.org/linux/man-pages/man3/wcscat.3.html)` — Added in POSIX.1-2008 TC2
- `[wcschr(3)](https://man7.org/linux/man-pages/man3/wcschr.3.html)` — Added in POSIX.1-2008 TC2
- `[wcscmp(3)](https://man7.org/linux/man-pages/man3/wcscmp.3.html)` — Added in POSIX.1-2008 TC2
- `[wcscpy(3)](https://man7.org/linux/man-pages/man3/wcscpy.3.html)` — Added in POSIX.1-2008 TC2
- `[wcscspn(3)](https://man7.org/linux/man-pages/man3/wcscspn.3.html)` — Added in POSIX.1-2008 TC2
- `[wcslen(3)](https://man7.org/linux/man-pages/man3/wcslen.3.html)` — Added in POSIX.1-2008 TC2
- `[wcsncat(3)](https://man7.org/linux/man-pages/man3/wcsncat.3.html)` — Added in POSIX.1-2008 TC2
- `[wcsncmp(3)](https://man7.org/linux/man-pages/man3/wcsncmp.3.html)` — Added in POSIX.1-2008 TC2
- `[wcsncpy(3)](https://man7.org/linux/man-pages/man3/wcsncpy.3.html)` — Added in POSIX.1-2008 TC2
- `[wcsnlen(3)](https://man7.org/linux/man-pages/man3/wcsnlen.3.html)` — Added in POSIX.1-2008 TC2
- `[wcspbrk(3)](https://man7.org/linux/man-pages/man3/wcspbrk.3.html)` — Added in POSIX.1-2008 TC2
- `[wcsrchr(3)](https://man7.org/linux/man-pages/man3/wcsrchr.3.html)` — Added in POSIX.1-2008 TC2
- `[wcsspn(3)](https://man7.org/linux/man-pages/man3/wcsspn.3.html)` — Added in POSIX.1-2008 TC2
- `[wcsstr(3)](https://man7.org/linux/man-pages/man3/wcsstr.3.html)` — Added in POSIX.1-2008 TC2
- `[wcstok(3)](https://man7.org/linux/man-pages/man3/wcstok.3.html)` — Added in POSIX.1-2008 TC2
- `[wmemchr(3)](https://man7.org/linux/man-pages/man3/wmemchr.3.html)` — Added in POSIX.1-2008 TC2
- `[wmemcmp(3)](https://man7.org/linux/man-pages/man3/wmemcmp.3.html)` — Added in POSIX.1-2008 TC2
- `[wmemcpy(3)](https://man7.org/linux/man-pages/man3/wmemcpy.3.html)` — Added in POSIX.1-2008 TC2
- `[wmemmove(3)](https://man7.org/linux/man-pages/man3/wmemmove.3.html)` — Added in POSIX.1-2008 TC2
- `[wmemset(3)](https://man7.org/linux/man-pages/man3/wmemset.3.html)` — Added in POSIX.1-2008 TC2
- `[write(2)](https://man7.org/linux/man-pages/man2/write.2.html)`

**Notes:**

- Fetching and setting `errno` is async-signal-safe if the signal handler saves `errno` on entry and restores it before returning.
- If a signal handler interrupts an unsafe function and terminates via `longjmp(3)` or `siglongjmp(3)`, subsequent calls to unsafe functions result in undefined behavior.
- POSIX.1-2001 and POSIX.1-2001 TC2 required `fpathconf(3)`, `pathconf(3)`, and `sysconf(3)` to be async-signal-safe, but this requirement was removed in POSIX.1-2008.
- If an application calls `fork(2)` from a signal handler and any `pthread_atfork(3)` handler calls a non-async-signal-safe function, behavior is undefined. A future revision may remove `fork(2)` from the list.
- Asynchronous signal handlers that call functions which are cancellation points and nest over regions of deferred cancellation may trigger cancellation, causing inconsistent state.

## See Also

- `[sigaction(2)](https://man7.org/linux/man-pages/man2/sigaction.2.html)`
- `[signal(7)](https://man7.org/linux/man-pages/man7/signal.7.html)`
- `[standards(7)](https://man7.org/linux/man-pages/man7/standards.7.html)`
