-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfoo.c
45 lines (41 loc) · 853 Bytes
/
foo.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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
int main(int argc, char **argv)
{
volatile int k, n, id;
volatile double x = 0, z;
n = atoi(argv[1]);
x = 0;
id = 0;
for (k = 0; k < n; k++)
{
id = fork();
if (id < 0)
{
printf(1, "Fork failed\n");
}
else if (id > 0)
{
//in parent
printf(1, "Parent %d creating child %d with priority %d\n", getpid(), id, 60-k);
set_priority(id, 60-k);
wait();
}
else
{
//in child
printf(1, "Child %d running\n", getpid());
break;
}
}
volatile double a, b;
a = 3.14;
b = 36.29;
for (z = 0; z < 9000000.0; z += 0.1)
{
x = x + a * b;
}
exit();
}