hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-10-17 12:24:17 +0200
committerhachem <im@hachem.wtf>2026-10-17 12:24:17 +0200
commit20a921db8bd8d5e99c0e9dcc72f22ac00a5e5222 (patch)
tree3454816f3642fe468f806aac495c04e55993b102 /user
parent6a5543bb8f1f535ca49737bcd7be0cafca3b2a08 (diff)
feat: fork/exec & wait
Diffstat (limited to 'user')
-rw-r--r--user/forktest.c28
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;
+}