diff options
| author | hachem <im@hachem.wtf> | 2026-10-17 12:24:17 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-10-17 12:24:17 +0200 |
| commit | 20a921db8bd8d5e99c0e9dcc72f22ac00a5e5222 (patch) | |
| tree | 3454816f3642fe468f806aac495c04e55993b102 /user/forktest.c | |
| parent | 6a5543bb8f1f535ca49737bcd7be0cafca3b2a08 (diff) | |
feat: fork/exec & wait
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; +} |
