Created
May 8, 2016 07:07
-
-
Save complxalgorithm/db24ae8fea471630b56dd1a242ad3c30 to your computer and use it in GitHub Desktop.
C program that ignores Ctrl-C for 5 seconds; afterward, the loop can be killed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <signal.h> | |
main () | |
{ | |
void (*oldHandler) (); /* To hold old handler value */ | |
int count = 0; /* Loop counter, initialized at 0 */ | |
oldHandler = signal (SIGINT, SIG_IGN); /* Ignore Control-C */ | |
printf ("I've started looping and I can't be killed with ^C\n"); | |
while(1) | |
{ | |
sleep (1); | |
printf("Still looping..."); | |
count++; | |
if (count == 5) | |
{ | |
signal (SIGINT, oldHandler); /* Restore old handler */ | |
printf ("I'm still looping but I can be killed with ^C now\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment