-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforkwait1b.c
More file actions
46 lines (34 loc) · 874 Bytes
/
Copy pathforkwait1b.c
File metadata and controls
46 lines (34 loc) · 874 Bytes
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
#include <stdio.h>
#include <comp421/yalnix.h>
int
main(int argc, char **argv)
{
(void)argc;
(void)argv;
int pid1, pid2;
int status;
int i;
setbuf(stdout, NULL);
printf("FORKWAIT> This program tests that Wait collects zombie processes\n");
printf("FORKWAIT> If no more FORKWAIT output, Fork does not work\n");
for (i = 0; i < 10; i++) {
if ((pid1 = Fork()) == 0)
{
printf("FORKWAIT> CHILD about to exit with 1234567\n");
Exit(1234567);
}
printf("FORKWAIT> PARENT: child pid = %d, &status = %p\n",
pid1, &status);
Delay(2);
pid2 = Wait(&status);
printf("FORKWAIT> Wait returned pid %d status %d\n", pid2, status);
if (pid2 != pid1 || status != 1234567) {
printf("Should have returned pid %d status 1234567!!\n", pid1);
Exit(1);
}
else {
printf("FORKWAIT> GOOD!\n");
}
}
Exit(0);
}