Add getppid(2)

This commit is contained in:
Mark
2020-07-22 23:13:29 +03:00
parent b09f7c34a3
commit 92acffb13b
5 changed files with 15 additions and 0 deletions
+1
View File
@@ -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,
+1
View File
@@ -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);
+1
View File
@@ -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
+1
View File
@@ -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;
+11
View File
@@ -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;