-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path001b.c
More file actions
76 lines (62 loc) · 2.07 KB
/
001b.c
File metadata and controls
76 lines (62 loc) · 2.07 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
..........................................................................................................................................
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<sys/times.h>
int i = 0;
void my_handler(int signal) {
if(signal == SIGVTALRM) {
i++;
long ticks = sysconf(_SC_CLK_TCK);
struct tms t;
times(&t);
printf("%d round - System CPU time : %.3f sec\n", i, (double)t.tms_stime/ticks);
fflush(stdout);
}
}
int main() {
signal(SIGVTALRM, 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_VIRTUAL, &timer, NULL);
while(1) {
for(int i=0; i<1000000000; i++) {
}
}
return 0;
}
/*----------------------------------OUTPUT----------------------------------------------------------------
1 round - System CPU time : 0.000 sec
2 round - System CPU time : 0.000 sec
3 round - System CPU time : 0.000 sec
4 round - System CPU time : 0.000 sec
5 round - System CPU time : 0.000 sec
6 round - System CPU time : 0.000 sec
7 round - System CPU time : 0.000 sec
8 round - System CPU time : 0.000 sec
9 round - System CPU time : 0.000 sec
10 round - System CPU time : 0.000 sec
11 round - System CPU time : 0.000 sec
12 round - System CPU time : 0.010 sec
13 round - System CPU time : 0.010 sec
14 round - System CPU time : 0.010 sec
15 round - System CPU time : 0.010 sec
16 round - System CPU time : 0.020 sec
17 round - System CPU time : 0.020 sec
*/