-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.c
More file actions
112 lines (97 loc) · 1.87 KB
/
test2.c
File metadata and controls
112 lines (97 loc) · 1.87 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "types.h"
#include "stat.h"
#include "user.h"
#include "perf.h"
struct perf p;
void timeConsuming(){
priority(1);
int init = uptime();
int curr = init;
int counter =0;
while(counter<30){
if(uptime()!=curr){
curr=uptime();
counter++;
}
}
exit(0);
}
void blockOnly(){
int i;
priority(1000);
for(i=0;i<30;i++)
sleep(1);
exit(0);
}
void mixed(){
int i;
priority(50);
int init = uptime();
int curr = init;
int counter =0;
for(i=0;i<5;i++){
while(counter<30){
if(uptime()!=curr){
curr=uptime();
counter++;
}
}
sleep(1);
}
exit(0);
}
/* struct printing */
void printPerf(struct perf p,int pid){
printf(2,"the pid is %d\n",pid );
printf(2,"the turnaround time is %d\n",(p.ttime-p.ctime));
printf(2,"the ttime is %d\n",p.ttime);
printf(2,"the stime is %d\n",p.stime);
printf(2,"the retime is %d\n",p.retime);
printf(2,"the rutime is %d\n\n",p.rutime);
}
int
main(int argc, char *argv[])
{
printf(1,"Sanity Test ! Calculating results.. please wait..\n\n");
/*creating 10 proccesses of CPU only*/
int i,pid;
int* status=0;
for(i=0;i<10;i++){
pid =fork();
if(pid==0){
timeConsuming();
}
}
/*creating 10 proccesses of Blocking only*/
for(i=0;i<10;i++){
pid =fork();
if(pid==0){
blockOnly();
}
}
/*creating 10 proccesses of mixed */
for(i=0;i<10;i++){
pid =fork();
if(pid==0)
mixed();
}
/* printing results and averages*/
int wait=0,turnaround=0,running=0,sleep=0;;
for(i=0;i<30;i++){
printPerf(p,wait_stat(status,&p));
wait+=p.retime;
turnaround+=(p.ttime-p.ctime);
running+=p.rutime;
sleep+=p.stime;
}
wait=wait/30;
turnaround=turnaround/30;
running=running/30;
sleep=sleep/30;
printf(1,"The avrages are: \n" );
printf(2,"waiting time: %d\n",wait);
printf(2,"turnaround time: %d\n",turnaround);
printf(2,"running time: %d\n",running);
printf(2,"sleeping time: %d\n",sleep);
return 1;
}