diff options
Diffstat (limited to 'user/forktest.c')
| -rw-r--r-- | user/forktest.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/user/forktest.c b/user/forktest.c new file mode 100644 index 0000000..14cc91b --- /dev/null +++ b/user/forktest.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <unistd.h> + +int main(void) +{ + printf("forktest: pid %d\n", getpid()); + + int pid = fork(); + if (pid < 0) + { + printf("fork failed\n"); + return 1; + } + + if (pid == 0) + { + printf(" child: pid %d, exec-ing membrk\n", getpid()); + exec("/usr/bin/membrk", 0); + printf(" child: exec failed\n"); + return 127; + } + + printf(" parent: forked child %d, waiting...\n", pid); + int status = -1; + int reaped = wait(&status); + printf(" parent: child %d exited with status %d\n", reaped, status); + return 0; +} |
