I am currently learning about signals in C and have a small program, that is supposed to not terminate upon receiving the SIGINT
signal using sigaction()
.
The code written below however does terminate, even though it looks fine to me. Maybe I am something missing. Does someone see, why it still terminates?
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void handle() { printf("%s%d%s", "I won't die....: ", getpid(), "\n"); }
int main() {
struct sigaction sa;
sa.sa_handler = handle;
int k = 0;
sigaction(SIGINT, &sa, NULL);
// signal(SIGINT, handle); //signal works just fine
while (k < 60) {
printf("%s", "sleeping... \n");
sleep(1);
k = k + 1;
}
}
Additional info: My OS is Windows, however I compile and execute the program in the Bash of a Linux subsystem.