考虑以下代码:
#include <signal.h>
#include <stdio.h>
void catch ()
{
printf("hi\n");
}
int main()
{
struct sigaction act;
act.sa_handler = catch;
sigaction(SIGINT, &act, NULL);
for(;;);
return 0;
}
当这个程序运行时。我第一次按CTRL-C时,它会打印“hi”。
但是第二次程序退出。这可能是什么原因?
我想要的是程序在每次发出信号时都会捕获它。