Can I use fprintf(stderr)
in a signal (SIGALRM) handler with glibc/linux?
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.