forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
foo.c
41 lines (34 loc) · 789 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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
int main(int argc, char *argv[]) {
int pid;
int k, n;
int x, z;
if (argc != 2) {
printf(2, "usage: %s n\n", argv[0]);
}
n = atoi(argv[1]);
for ( k = 0; k < n; k++ ) {
pid = fork ();
if ( pid < 0 ) {
printf(1, "%d failed in fork!\n", getpid());
exit();
} else if (pid == 0) {
// child
printf(1, "Child (with pid=%d) created\n",getpid());
for ( z = 0; z < 100.0; z += 0.1 ){
x = x + 3.14 * 89.64; // useless calculations to consume CPU time
if((z== (int)z) && ((z%10) ==0)){
printf(1, "[pid=%d] %d \n",getpid(),z);
}
}
exit();
}
}
for (k = 0; k < n; k++) {
wait();
}
exit();
}