This source file includes following definitions.
- print
- forktest
- main
1
2
3
4 #include "kernel/types.h"
5 #include "kernel/stat.h"
6 #include "user/user.h"
7
8 #define N 1000
9
10 void
11 print(const char *s)
12 {
13 write(1, s, strlen(s));
14 }
15
16 void
17 forktest(void)
18 {
19 int n, pid;
20
21 print("fork test\n");
22
23 for (n = 0; n < N; n++) {
24 pid = fork();
25 if (pid < 0)
26 break;
27 if (pid == 0)
28 exit(0);
29 }
30
31 if (n == N) {
32 print("fork claimed to work N times!\n");
33 exit(1);
34 }
35
36 for (; n > 0; n--) {
37 if (wait(0) < 0) {
38 print("wait stopped early\n");
39 exit(1);
40 }
41 }
42
43 if (wait(0) != -1) {
44 print("wait got too many\n");
45 exit(1);
46 }
47
48 print("fork test OK\n");
49 }
50
51 int
52 main(void)
53 {
54 forktest();
55 exit(0);
56 }