From 8a19547957a86bed3f58c9abc1ac218d04698faf Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 8 Apr 2025 10:39:48 -0400 Subject: break apart c libaray --- user/lib/spawn.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 user/lib/spawn.c (limited to 'user/lib/spawn.c') diff --git a/user/lib/spawn.c b/user/lib/spawn.c new file mode 100644 index 0000000..78b1a53 --- /dev/null +++ b/user/lib/spawn.c @@ -0,0 +1,32 @@ +#include +#include +#include + +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); +} -- cgit v1.2.3-freya