-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlottery3.c
43 lines (36 loc) · 923 Bytes
/
lottery3.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
#include "types.h"
#include "user.h"
// test the lottery ticket scheduler
// This test makes sure that the process with the highest priority gets to run the most.
// This test also makes sure that processes with a priority of 0 (lowest possible) still gets to run.
#define X 10000
int
main(int argc, char *argv[])
{
printf(1, "lottery test 3\n");
// 20 processes with equal nice values
int pid;
int i;
for (i = 20; i >= 0; i--) {
pid = fork();
if (pid == 0) {
int count = 0;
int laps = 0;
while(1) {
// since prints are expensive, only print after X iterations
count++;
if (count > X) {
laps++;
count = 0;
printf(1, "%d\n", i);
}
// keep priority at i
if (nice(0) < 5) // keep around 4-6
nice(2);
printf(1, "%d\n", i); // process number
}
}
}
while(1) {}
exit();
}