-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforktest3.c
More file actions
55 lines (45 loc) · 841 Bytes
/
forktest3.c
File metadata and controls
55 lines (45 loc) · 841 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
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <comp421/yalnix.h>
void
recurse(char *who, int i)
{
char waste[1024]; /* use up stack space in the recursion */
char *mem = (char *)malloc(2048); /* use up heap space */
int j;
(void)waste;
printf("mem %p\n", mem);
for (j = 0; j < 1024; j++)
waste[j] = 'a';
Delay(1);
printf("%s %d\n", who, i);
if (i == 0)
{
printf("Done with recursion\n");
return;
}
else {
Fork();
recurse(who, i - 1);
}
}
int
main(int argc, char **argv)
{
(void)argc;
(void)argv;
int pid;
setbuf(stdout, NULL);
printf("BEFORE\n");
if ((pid = Fork()) == 0)
{
printf("CHILD\n");
recurse("child", 33);
}
else
{
printf("PARENT: child pid = %d\n", pid);
recurse("parent", 33);
}
Exit(0);
}