Reputation: 1
Is there a way to handle SIGINT only 2 times and return it to default using SA_RESETHAND? We must use sigaction, and make our handler reinstall by itself 2 times and then install flags to resethand. But there's a question: how to reinstall my handler only 2 times and how to use RESETHAND in this situation? n-1?
void sig_int(int sig)
{
printf(" -> Ctrl-C\n");
struct sigaction act;
act.sa_handler = SIG_DFL;
if(sigaction(SIGINT, &act, NULL) < 0)
{
exit(-1);
}
}
int main()
{
struct sigaction act;
act.sa_handler = sig_int;
if(sigaction(SIGINT, &act, NULL) < 0)
{
exit(-1);
}
while(1)
{
sleep(1);
}
return 0;
}
Upvotes: 0
Views: 1342