summaryrefslogtreecommitdiff
path: root/ulib/spawn.c
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-03 12:31:21 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-03 12:31:21 -0400
commita524eb3846aac4d1b38f08cba49ff3503107042f (patch)
treedbe81fccf975f646a681e4fdcebd227cdfb98774 /ulib/spawn.c
parentnew libs (diff)
downloadcomus-a524eb3846aac4d1b38f08cba49ff3503107042f.tar.gz
comus-a524eb3846aac4d1b38f08cba49ff3503107042f.tar.bz2
comus-a524eb3846aac4d1b38f08cba49ff3503107042f.zip
move old kernel code (for now) into kernel/old, trying to get long mode
Diffstat (limited to 'ulib/spawn.c')
-rw-r--r--ulib/spawn.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/ulib/spawn.c b/ulib/spawn.c
new file mode 100644
index 0000000..78b1a53
--- /dev/null
+++ b/ulib/spawn.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <error.h>
+#include <unistd.h>
+
+int wait(int32_t *status)
+{
+ return (waitpid(0, status));
+}
+
+int spawn(uint_t prog, char **args)
+{
+ int32_t pid;
+
+ pid = fork();
+ if (pid != 0) {
+ // failure, or we are the parent
+ return (pid);
+ }
+
+ // we are the child
+ pid = getpid();
+
+ // child inherits parent's priority level
+
+ exec(prog, args);
+
+ // uh-oh....
+
+ fprintf(stderr, "Child %d exec() #%u failed\n", pid, prog);
+
+ exit(EXIT_FAILURE);
+}