still serv_close bug...
[mit-jos.git] / user / forktree.c
blobbcccd6eb9f0bd0e912f50e7cbe34c668b5eb316f
1 // Fork a binary tree of processes and display their structure.
3 #include <inc/lib.h>
5 #define DEPTH 3
7 void forktree(const char *cur);
9 void
10 forkchild(const char *cur, char branch)
12 char nxt[DEPTH+1];
14 if (strlen(cur) >= DEPTH)
15 return;
17 snprintf(nxt, DEPTH+1, "%s%c", cur, branch);
18 if (fork() == 0) {
19 forktree(nxt);
20 exit();
24 void
25 forktree(const char *cur)
27 cprintf("%04x: I am '%s'\n", sys_getenvid(), cur);
29 forkchild(cur, '0');
30 forkchild(cur, '1');
33 void
34 umain(void)
36 forktree("");