diff --git a/arch/amd64/syscall.c b/arch/amd64/syscall.c index 0ebca0a..b38a951 100644 --- a/arch/amd64/syscall.c +++ b/arch/amd64/syscall.c @@ -82,6 +82,7 @@ void *syscall_table[256] = { [SYSCALL_NR_GETPGID] = sys_getpgid, [SYSCALL_NR_SETPGID] = sys_setpgid, [SYSCALL_NR_SIGALTSTACK] = sys_sigaltstack, + [SYSCALL_NR_GETPPID] = sys_getppid, // System [SYSCALL_NR_SYNC] = sys_sync, diff --git a/include/sys/sys_proc.h b/include/sys/sys_proc.h index ba683c1..f3b8efe 100644 --- a/include/sys/sys_proc.h +++ b/include/sys/sys_proc.h @@ -10,6 +10,7 @@ void sys_sigreturn(void); int sys_clone(int (*entry) (void *), void *stack, int flags, void *arg); int sys_execve(const char *path, const char **argp, const char **envp); pid_t sys_getpid(void); +pid_t sys_getppid(void); uid_t sys_getuid(void); gid_t sys_getgid(void); diff --git a/include/user/syscall.h b/include/user/syscall.h index 5547839..393ca52 100644 --- a/include/user/syscall.h +++ b/include/user/syscall.h @@ -51,6 +51,7 @@ #define SYSCALL_NR_SETUID 105 #define SYSCALL_NR_SETGID 106 #define SYSCALL_NR_SETPGID 109 +#define SYSCALL_NR_GETPPID 110 #define SYSCALL_NR_GETPGID 121 #define SYSCALL_NR_SIGALTSTACK 131 #define SYSCALL_NRX_WAITPID 247 diff --git a/sys/execve.c b/sys/execve.c index 703398e..80ddfcc 100644 --- a/sys/execve.c +++ b/sys/execve.c @@ -218,6 +218,7 @@ int sys_execve(const char *path, const char **argv, const char **envp) { } proc->first_child = NULL; proc->next_child = NULL; + // TODO: automatically parent all subsequent processes to init (1) proc->parent = NULL; proc->sigq = 0; diff --git a/sys/thread.c b/sys/thread.c index b732a9e..180a87a 100644 --- a/sys/thread.c +++ b/sys/thread.c @@ -875,6 +875,17 @@ pid_t sys_getpid(void) { return thread_self->proc->pid; } +pid_t sys_getppid(void) { + _assert(thread_self && thread_self->proc); + struct process *proc = thread_self->proc; + if (!proc->parent) { + _assert(proc->pid == 1); + return 1; + } else { + return proc->parent->pid; + } +} + pid_t sys_getpgid(pid_t pid) { struct process *proc;