-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewtest.c
63 lines (51 loc) · 1.57 KB
/
newtest.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
57
58
59
60
61
62
63
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
int PScheduler(void) {
int pid, ret_pid=-1, exit_status=100;
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 1 to 63\n");
printf(1, "\n Step 2: 1 is the highest priority. All processes have a default priority of 20\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(60-20*i);
for (j=0;j<50000;j++) {
for(k=0;k<10000;k++) {
asm("nop"); }}
printf(1, "\n child# %d with priority %d has finished! \n",getpid(),60-20*i);
exit(0);
}
else {
printf(2," \n Error \n");
exit(-1);
}
}
if(pid > 0) {
for (i = 0; i < 3; i++) {
ret_pid = wait(&exit_status);
}
printf(1,"\n if processes with highest priority finished first then its correct \n");
}
return ret_pid;
}
int main(int argc, char *argv[])
{
int PScheduler(void);
printf(1, "\n This program tests the correctness of your lab#1\n");
if (atoi(argv[1]) == 1)
printf(1, "already tested");
else if (atoi(argv[1]) == 2)
printf(1, "already tested");
else if (atoi(argv[1]) == 3)
PScheduler();
else
printf(1, "\ntype \"lab1 1\" to test exit and wait, \"lab1 2\" to test waitpid and \"lab1 3\" to test the priority scheduler \n");
exit(0);
}