From b1fb19b6df716c0ad30b05236c356bc34457c70b Mon Sep 17 00:00:00 2001 From: rsc Date: Thu, 23 Aug 2007 14:40:30 +0000 Subject: Use parent pointer instead of ppid. --- proc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'proc.c') diff --git a/proc.c b/proc.c index 79fb702..d74a5e9 100644 --- a/proc.c +++ b/proc.c @@ -118,7 +118,7 @@ copyproc(struct proc *p) np->tf = (struct trapframe*)(np->kstack + KSTACKSIZE) - 1; if(p){ // Copy process state from p. - np->ppid = p->pid; + np->parent = p; memmove(np->tf, p->tf, sizeof(*np->tf)); np->sz = p->sz; @@ -366,15 +366,13 @@ proc_exit(void) acquire(&proc_table_lock); - // Wake up waiting parent. - for(p = proc; p < &proc[NPROC]; p++) - if(p->pid == cp->ppid) - wakeup1(p); + // Parent might be sleeping in proc_wait. + wakeup1(cp->parent); // Pass abandoned children to init. for(p = proc; p < &proc[NPROC]; p++){ - if(p->ppid == cp->pid){ - p->ppid = initproc->pid; + if(p->parent == cp){ + p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } @@ -403,7 +401,7 @@ proc_wait(void) p = &proc[i]; if(p->state == UNUSED) continue; - if(p->ppid == cp->pid){ + if(p->parent == cp){ if(p->state == ZOMBIE){ // Found one. kfree(p->mem, p->sz); @@ -411,7 +409,7 @@ proc_wait(void) pid = p->pid; p->state = UNUSED; p->pid = 0; - p->ppid = 0; + p->parent = 0; p->name[0] = 0; release(&proc_table_lock); return pid; -- cgit v1.2.3