I'm trying to learn signal handling in FreeBSD, and so I made this little apparently-not-functional program:
I swear I have no idea what's wrong with it, because
Weirdly enough, I don't even see that error message I put. That means it was able to install the handler then, right? No? Could it be that it got fooled by the OS too?
I should also mention that I'm not very experienced with C either, so I apologize if I made any stupid mistakes. I'm just trying to figure this out to fix a bigger program that relies on the same thing. It'd work just fine on Linux.
C:
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <err.h>
void handler(int sig) {
printf("Boo!\n");
}
int main(void) {
printf("Send any signal to continue, or USR1+10 to get a surprise...\n");
if (signal(SIGUSR1+10, handler) == SIG_ERR)
err(1, "Failed to install signal handler!");
while (1) {
printf("Waiting...\n");
sleep(5);
}
return 0;
}
I swear I have no idea what's wrong with it, because
pkill USR1+10 sighandler simply doesn't work at all. Instead of sending the signal to the program and letting it handle it, it just kills it entirely instead. No matter what I try, it just dies instead of printing the correct message.Weirdly enough, I don't even see that error message I put. That means it was able to install the handler then, right? No? Could it be that it got fooled by the OS too?
I should also mention that I'm not very experienced with C either, so I apologize if I made any stupid mistakes. I'm just trying to figure this out to fix a bigger program that relies on the same thing. It'd work just fine on Linux.