-
Notifications
You must be signed in to change notification settings - Fork 0
/
24_Signal-SIGALRM.c
53 lines (47 loc) · 1000 Bytes
/
24_Signal-SIGALRM.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Program in C, that gives an alarm massage after every 2 seconds until the counter has exceeded 10.
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void fun(int signum)
{
printf("Alarm : ");
// alarm(2);
fflush(stdout);
}
int main()
{
int count = 0;
signal(SIGALRM, fun);
alarm(2);
while (1)
{
count++;
pause();
printf("Count = %d\n", count);
if (count >= 10)
break;
}
}
/*
Output:
[With alarm(2)]
s4shibam@SHIBAM:~/OS$ gcc 24_Signal-SIGALRM.c
s4shibam@SHIBAM:~/OS$ ./a.out
Alarm : Count = 1
Alarm : Count = 2
Alarm : Count = 3
Alarm : Count = 4
Alarm : Count = 5
Alarm : Count = 6
Alarm : Count = 7
Alarm : Count = 8
Alarm : Count = 9
Alarm : Count = 10
s4shibam@SHIBAM:~/OS$
[Without alarm(2)]
s4shibam@SHIBAM:~/OS$ gcc 24_Signal-SIGALRM.c
s4shibam@SHIBAM:~/OS$ ./a.out
Alarm : Count = 1
^C
s4shibam@SHIBAM:~/OS$
*/