Code in question first (minimized case):
#include <stdio.h>
#include <signal.h>
int counter = 0;
void react_to_signal(int n) {
fprintf(stderr, "Caught!\n");
counter++;
}
int main(int argc, char** argv) {
signal(SIGINFO, react_to_signal);
while (1) {
printf("%d\n", counter);
}
return 0;
}
I run the code, it loops as it should, printing out 0. Then in another shell..
kill -s SIGINFO <pid_of_my_process>
Signal is delivered, c
is incremented .. but the fprintf
doesn't happen.
Why is this so? In what environment/context does handler code run? Where can I read up on this?