-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab2_test.c
56 lines (43 loc) · 1.43 KB
/
lab2_test.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
54
55
56
#include "types.h"
#include "user.h"
int main(int argc, char *argv[])
{
int PScheduler(void);
printf(1, "\n This program tests the correctness of your lab#2\n");
PScheduler();
return 0;
}
int PScheduler(void){
// use this part to test the priority scheduler. Assuming that the priorities range between range between 0 to 31
// 0 is the highest priority and 31 is the lowest priority.
int pid;
int i,j,k;
printf(1, "\n Step 2: testing the priority scheduler and setpriority(int priority)) systema call:\n");
printf(1, "\n Step 2: Assuming that the priorities range between range between 0 to 31\n");
printf(1, "\n Step 2: 0 is the highest priority. All processes have a default priority of 10\n");
printf(1, "\n Step 2: The parent processes will switch to priority 0\n");
setpriority(0);
for (i = 0; i < 3; i++) {
pid = fork();
if (pid > 0 ) {
continue;}
else if ( pid == 0) {
setpriority(30-10*i);
for (j=0;j<50000;j++) {
for(k=0;k<1000;k++) {
asm("nop"); }}
printf(1, "\n child# %d with priority %d has finished! \n",getpid(),30-10*i);
exit(0);
}
else {
printf(2," \n Error \n");
}
}
if(pid > 0) {
for (i = 0; i < 3; i++) {
wait(0);
}
printf(1,"\n if processes with highest priority finished first then its correct \n");
}
exit(0);
return 0;}