From b61c07af798557eff4333716c917c99a4f0c13c6 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 13 Oct 2025 16:14:02 -0400 Subject: kern: proc: Add initial waitpid() syscall Signed-off-by: Ian Moffett --- src/sys/os/os_proc.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/sys/os') diff --git a/src/sys/os/os_proc.c b/src/sys/os/os_proc.c index 4ee4fd8..764b3f2 100644 --- a/src/sys/os/os_proc.c +++ b/src/sys/os/os_proc.c @@ -439,3 +439,35 @@ sys_getargv(struct syscall_args *scargs) arg = envblk->argv[argno]; return copyoutstr(arg, u_buf, maxlen); } + +/* + * Wait for a child to complete + * + * ARG0: PID + * ARG1: Status + * ARG2: Options + */ +scret_t +sys_waitpid(struct syscall_args *scargs) +{ + int pid = SCARG(scargs, int, 0); + int *u_status = SCARG(scargs, int *, 1); + int status = 0; + int error = 0; + struct proc *proc, *self; + + if ((proc = proc_lookup(pid)) == NULL) { + return -ESRCH; + } + + if (u_status != NULL) { + error = copyout(&status, u_status, sizeof(*u_status)); + } + if (error < 0) { + return error; + } + + self = proc_self(); + proc_sleep(self); + return 0; +} -- cgit v1.2.3