diff --git a/apps/init.c b/apps/init.c index 9964d791..9e485d40 100644 --- a/apps/init.c +++ b/apps/init.c @@ -47,5 +47,5 @@ int main() return 1; } - while (1) { waitpid(-1, NULL, 0); } + while (1) wait(NULL); } diff --git a/kernel/src/sys/id.cpp b/kernel/src/sys/id.cpp index 43dccdca..fd5dfac7 100644 --- a/kernel/src/sys/id.cpp +++ b/kernel/src/sys/id.cpp @@ -5,3 +5,8 @@ Result sys_getpid(Registers*, SyscallArgs) { return Scheduler::current()->id; } + +Result sys_getppid(Registers*, SyscallArgs) +{ + return Scheduler::current()->parent_id; +} diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h index 362924f4..71cf0798 100644 --- a/libc/include/sys/wait.h +++ b/libc/include/sys/wait.h @@ -14,6 +14,9 @@ extern "C" /* Wait for a child process to exit. */ pid_t waitpid(pid_t pid, int* status, int options); + /* Wait for any child process to exit. */ + pid_t wait(int* status); + #ifdef __cplusplus } #endif diff --git a/libc/include/unistd.h b/libc/include/unistd.h index ccadde52..e9fe0bc3 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -25,6 +25,9 @@ extern "C" /* Return the current process' process ID. */ pid_t getpid(void); + /* Return the current process' parent process ID. */ + pid_t getppid(void); + /* Replace the current process with another one. On success, does not return. */ int execv(const char* path, char* const* argv); diff --git a/libc/src/sys/wait.cpp b/libc/src/sys/wait.cpp index 519a5b88..2acef314 100644 --- a/libc/src/sys/wait.cpp +++ b/libc/src/sys/wait.cpp @@ -10,4 +10,9 @@ extern "C" long rc = syscall(SYS_waitpid, pid, status, options); __errno_return(rc, pid_t); } + + pid_t wait(int* status) + { + return waitpid(-1, status, 0); + } } diff --git a/libc/src/unistd.cpp b/libc/src/unistd.cpp index 23f6e178..f01d5cfa 100644 --- a/libc/src/unistd.cpp +++ b/libc/src/unistd.cpp @@ -19,6 +19,11 @@ extern "C" return (pid_t)syscall(SYS_getpid); } + pid_t getppid(void) + { + return (pid_t)syscall(SYS_getppid); + } + int execv(const char* path, char* const* argv) { long rc = syscall(SYS_exec, path, argv); diff --git a/libluna/include/luna/Syscall.h b/libluna/include/luna/Syscall.h index 4950a6e7..4179622e 100644 --- a/libluna/include/luna/Syscall.h +++ b/libluna/include/luna/Syscall.h @@ -2,7 +2,7 @@ #define enumerate_syscalls(_e) \ _e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \ - _e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid) + _e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid) _e(getppid) enum Syscalls {