From 20a921db8bd8d5e99c0e9dcc72f22ac00a5e5222 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 17 Oct 2026 12:24:17 +0200 Subject: feat: fork/exec & wait --- user/forktest.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 user/forktest.c (limited to 'user/forktest.c') 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 +#include + +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; +} -- cgit v1.3