-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_bound.c
48 lines (35 loc) · 1018 Bytes
/
io_bound.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
#include<unistd.h>
#include<stdio.h>
#include<sys/time.h>
#define ON 1
#define OFF 0
#define WAIT_TIME 120 //sec
#define SEC_TO_USEC 1000000
void start_to_count_number_of_process_switches() {
syscall(352);
}
unsigned int stop_to_count_number_of_process_switches() {
unsigned int ret;
ret = syscall(353);
return ret;
}
int main() {
unsigned int a;
int loop_switch = ON;
int b = 0;
struct timeval start_tv;
struct timeval now_tv;
start_to_count_number_of_process_switches();
gettimeofday(&start_tv, NULL);
while(loop_switch) {
usleep(10);
printf("[%d ]", b++);
gettimeofday(&now_tv, NULL);
int diff;
diff = (now_tv.tv_sec - start_tv.tv_sec) * SEC_TO_USEC + (now_tv.tv_usec - start_tv.tv_usec);
if(diff >= WAIT_TIME * SEC_TO_USEC) loop_switch = OFF;
}
a = stop_to_count_number_of_process_switches();
printf("\nDuring the pass time the process makes %u times process switches.\n", a);
return 0;
}