Loading sys/process.c +13 −14 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ static int _process_number = 0; // virtual task for idle struct process _proc_idle_task = { .pid = 0, .parent = NULL, .dir_list = NULL, .state = PROCESS_STATE_RUNNING, .acnt = NULL, Loading Loading @@ -105,7 +106,7 @@ struct process *process_alloc() { proc->pid = process_get_pid(); proc->pgid = 1; // group of init? proc->ppid = 0; proc->parent = NULL; proc->state = PROCESS_STATE_CREATE; proc->ctty = NULL; Loading Loading @@ -262,7 +263,7 @@ pid_t sys_fork() { newproc = process_alloc(); newproc->pgid = cur->pgid; newproc->ppid = cur->pid; newproc->parent = cur; for(i=0; i<PROCESS_MAX_FILE; i++) { // for each valid file descriptor, increment usage counter newproc->files[i] = cur->files[i]; Loading Loading @@ -366,7 +367,7 @@ pid_t sys_getpid() { } pid_t sys_getppid() { return process_get_current()->ppid; return process_get_ppid(); } Loading Loading @@ -798,19 +799,17 @@ pid_t sys_getpgid(pid_t pid) { } int process_is_descendant(struct process *proc, pid_t other) { int process_is_descendant(struct process *proc, pid_t otherpid) { struct process *other = process_from_pid(otherpid); if(other != NULL) { struct process *cur; for(cur=proc; cur!=NULL && cur->ppid != other && cur->pid != 1; cur = process_from_pid(cur->ppid)); for(cur=proc; cur != NULL && cur->parent != other; cur = cur->parent); if(cur != NULL) { if(cur->ppid == other) if(cur != NULL && cur->parent->pid == otherpid) return 1; } else { printk(LOG_DEBUG, "proc: bad process hierarchy\n"); } return 0; } Loading @@ -827,7 +826,7 @@ static void copy_proc_user(struct process *proc, void *userbuf) { uinfo->uticks = proc->uticks; uinfo->pid = proc->pid; uinfo->ppid = proc->ppid; uinfo->ppid = process_get_ppid(proc); uinfo->state = proc->state; uinfo->exit_status = proc->exit_status; Loading sys/process.h +11 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,9 @@ struct process { pid_t pid; pid_t pgid; // parent, or NULL (no other process than swaper and init should use NULL) struct process *parent; // virtual memory managing data : struct addr_space addr_space; struct page_dir *dir_list; Loading @@ -78,7 +81,6 @@ struct process { sigset_t sig_pending; struct sigaction sig_array[SIGNAL_INDEX_MAX]; pid_t ppid; int state; int exit_status; // only valid when state is PROCESS_STATE_ZOMBIE Loading Loading @@ -181,6 +183,14 @@ static inline struct process *process_get_current() { } /** * Return the pid of the parent process, or 0 if not available. */ static inline pid_t process_get_ppid() { return _proc_current->parent == NULL ? 0 : _proc_current->parent->pid; } /** * Run given process, switching context from current kernel context to * process context_info. Loading sys/scheduler.c +2 −2 Original line number Diff line number Diff line Loading @@ -212,7 +212,7 @@ pid_t sys_wait(int *status) { // do not return before a child is in Zombie state int ret = 0; pid_t ppid = process_get_current()->pid; struct process *proc = process_get_current(); while(ret == 0) { int i; Loading @@ -222,7 +222,7 @@ pid_t sys_wait(int *status) { for(i=0; i<SCHED_MAX_TASKS; i++) { //printk(LOG_DEBUG, "task %d", i); //printk(LOG_DEBUG, "->%p\n", _tasks[i]); if(_tasks[i] != NULL && _tasks[i]->ppid == ppid) { if(_tasks[i] != NULL && _tasks[i]->parent == proc) { if(_tasks[i]->state == PROCESS_STATE_ZOMBIE) { ret = _tasks[i]->pid; if(status != NULL) Loading Loading
sys/process.c +13 −14 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ static int _process_number = 0; // virtual task for idle struct process _proc_idle_task = { .pid = 0, .parent = NULL, .dir_list = NULL, .state = PROCESS_STATE_RUNNING, .acnt = NULL, Loading Loading @@ -105,7 +106,7 @@ struct process *process_alloc() { proc->pid = process_get_pid(); proc->pgid = 1; // group of init? proc->ppid = 0; proc->parent = NULL; proc->state = PROCESS_STATE_CREATE; proc->ctty = NULL; Loading Loading @@ -262,7 +263,7 @@ pid_t sys_fork() { newproc = process_alloc(); newproc->pgid = cur->pgid; newproc->ppid = cur->pid; newproc->parent = cur; for(i=0; i<PROCESS_MAX_FILE; i++) { // for each valid file descriptor, increment usage counter newproc->files[i] = cur->files[i]; Loading Loading @@ -366,7 +367,7 @@ pid_t sys_getpid() { } pid_t sys_getppid() { return process_get_current()->ppid; return process_get_ppid(); } Loading Loading @@ -798,19 +799,17 @@ pid_t sys_getpgid(pid_t pid) { } int process_is_descendant(struct process *proc, pid_t other) { int process_is_descendant(struct process *proc, pid_t otherpid) { struct process *other = process_from_pid(otherpid); if(other != NULL) { struct process *cur; for(cur=proc; cur!=NULL && cur->ppid != other && cur->pid != 1; cur = process_from_pid(cur->ppid)); for(cur=proc; cur != NULL && cur->parent != other; cur = cur->parent); if(cur != NULL) { if(cur->ppid == other) if(cur != NULL && cur->parent->pid == otherpid) return 1; } else { printk(LOG_DEBUG, "proc: bad process hierarchy\n"); } return 0; } Loading @@ -827,7 +826,7 @@ static void copy_proc_user(struct process *proc, void *userbuf) { uinfo->uticks = proc->uticks; uinfo->pid = proc->pid; uinfo->ppid = proc->ppid; uinfo->ppid = process_get_ppid(proc); uinfo->state = proc->state; uinfo->exit_status = proc->exit_status; Loading
sys/process.h +11 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,9 @@ struct process { pid_t pid; pid_t pgid; // parent, or NULL (no other process than swaper and init should use NULL) struct process *parent; // virtual memory managing data : struct addr_space addr_space; struct page_dir *dir_list; Loading @@ -78,7 +81,6 @@ struct process { sigset_t sig_pending; struct sigaction sig_array[SIGNAL_INDEX_MAX]; pid_t ppid; int state; int exit_status; // only valid when state is PROCESS_STATE_ZOMBIE Loading Loading @@ -181,6 +183,14 @@ static inline struct process *process_get_current() { } /** * Return the pid of the parent process, or 0 if not available. */ static inline pid_t process_get_ppid() { return _proc_current->parent == NULL ? 0 : _proc_current->parent->pid; } /** * Run given process, switching context from current kernel context to * process context_info. Loading
sys/scheduler.c +2 −2 Original line number Diff line number Diff line Loading @@ -212,7 +212,7 @@ pid_t sys_wait(int *status) { // do not return before a child is in Zombie state int ret = 0; pid_t ppid = process_get_current()->pid; struct process *proc = process_get_current(); while(ret == 0) { int i; Loading @@ -222,7 +222,7 @@ pid_t sys_wait(int *status) { for(i=0; i<SCHED_MAX_TASKS; i++) { //printk(LOG_DEBUG, "task %d", i); //printk(LOG_DEBUG, "->%p\n", _tasks[i]); if(_tasks[i] != NULL && _tasks[i]->ppid == ppid) { if(_tasks[i] != NULL && _tasks[i]->parent == proc) { if(_tasks[i]->state == PROCESS_STATE_ZOMBIE) { ret = _tasks[i]->pid; if(status != NULL) Loading