SIGINT signal 받았을 때 sigaction()을 이용하여 loop 종료시키고 빠져나오는 예제
#include <stdio.h>
#include <signal.h>
#include <string.h>
static int exit=0;
void sig_handler()
{
exit = 1;
}
void main()
{
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = sig_handler;
sigaction(SIGINT, &act, 0);
while(1)
{
sleep(1);
printf("loop\n");
if(exit)
{
printf("exit!\n");
break;
}
}
}