Search code examples
linuxsignalshandlerglibc

linux/glibc. Can I use fprintf in signal handler?


Can I use fprintf(stderr) in a signal (SIGALRM) handler with glibc/linux?


Solution

  • No you cannot. Check the manpage signal(7) for a list of async-signal-safe functions. fprintf is not included in that list.

    If you don't need formatting then you can use write(STDERR_FILENO, <buf>, <buflen>) to write to stderr.