-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path001a.c
More file actions
60 lines (47 loc) · 1.46 KB
/
001a.c
File metadata and controls
60 lines (47 loc) · 1.46 KB
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
54
55
56
57
58
59
60
/*
..........................................................................................................................................
Name : 001.c
Author : SHRUTI VERMA
Description : Write a separate program (for each time domain) to set a interval timer in 10sec and
10micro second
a. ITIMER_REAL
b. ITIMER_VIRTUAL
c. ITIMER_PROF
Date : 29 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include<sys/time.h>
#include<time.h>
int i = 0;
void my_handler(int signal) {
if(signal == SIGALRM) {
i++;
time_t now;
time(&now);
printf("%d round : %s\n", i, ctime(&now));
fflush(stdout);
}
}
int main() {
signal(SIGALRM, my_handler);
struct itimerval timer;
timer.it_value.tv_sec = 10;
timer.it_value.tv_usec = 0 ;
timer.it_interval.tv_sec = 10;
timer.it_interval.tv_usec = 10;
setitimer(ITIMER_REAL, &timer, NULL);
while(1) {
pause();
}
return 0;
}
/*----------------------------------OUTPUT----------------------------------------------------------------
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./1a
1 round : Mon Sep 29 12:33:10 2025
2 round : Mon Sep 29 12:33:20 2025
3 round : Mon Sep 29 12:33:30 2025
*/