1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <signal.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
time_t startTime;
time_t endTime;
void handler(int sig)
{
time_t now;
now = time(NULL);
if (now < endTime)
{
printf("Not Interrupted..\n");
signal(SIGINT, handler);
}
else
{
printf("changed back to default handler\n");
signal(SIGINT, SIG_DFL);
}
}
int main()
{
startTime = time(NULL);
endTime = startTime + 5;
signal(SIGINT, handler);
for (;;)
{
printf("ready...\n");
usleep(200000);
}
return 0;
} |
Partager