Code in question first (minimized case):
#include
#include
int counter = 0;
void react_to_signal(int n) {
fprintf(stde
In short: you cannot safely use printf
within a signal handler.
There's a list of authorized functions in signal handler's man page. There is not fprintf
in it.
That's because this function is not reentrant, mainly because it can use malloc
and free
.
See this post for a detailed explanation.
You may need to fflush stderr to get the message to write before the program exits.