Skip to content
Snippets Groups Projects
Commit b1fb19b6 authored by rsc's avatar rsc
Browse files

Use parent pointer instead of ppid.
parent 3a057d12
No related branches found
No related tags found
No related merge requests found
...@@ -118,7 +118,7 @@ copyproc(struct proc *p) ...@@ -118,7 +118,7 @@ copyproc(struct proc *p)
np->tf = (struct trapframe*)(np->kstack + KSTACKSIZE) - 1; np->tf = (struct trapframe*)(np->kstack + KSTACKSIZE) - 1;
if(p){ // Copy process state from p. if(p){ // Copy process state from p.
np->ppid = p->pid; np->parent = p;
memmove(np->tf, p->tf, sizeof(*np->tf)); memmove(np->tf, p->tf, sizeof(*np->tf));
np->sz = p->sz; np->sz = p->sz;
...@@ -366,15 +366,13 @@ proc_exit(void) ...@@ -366,15 +366,13 @@ proc_exit(void)
acquire(&proc_table_lock); acquire(&proc_table_lock);
// Wake up waiting parent. // Parent might be sleeping in proc_wait.
for(p = proc; p < &proc[NPROC]; p++) wakeup1(cp->parent);
if(p->pid == cp->ppid)
wakeup1(p);
// Pass abandoned children to init. // Pass abandoned children to init.
for(p = proc; p < &proc[NPROC]; p++){ for(p = proc; p < &proc[NPROC]; p++){
if(p->ppid == cp->pid){ if(p->parent == cp){
p->ppid = initproc->pid; p->parent = initproc;
if(p->state == ZOMBIE) if(p->state == ZOMBIE)
wakeup1(initproc); wakeup1(initproc);
} }
...@@ -403,7 +401,7 @@ proc_wait(void) ...@@ -403,7 +401,7 @@ proc_wait(void)
p = &proc[i]; p = &proc[i];
if(p->state == UNUSED) if(p->state == UNUSED)
continue; continue;
if(p->ppid == cp->pid){ if(p->parent == cp){
if(p->state == ZOMBIE){ if(p->state == ZOMBIE){
// Found one. // Found one.
kfree(p->mem, p->sz); kfree(p->mem, p->sz);
...@@ -411,7 +409,7 @@ proc_wait(void) ...@@ -411,7 +409,7 @@ proc_wait(void)
pid = p->pid; pid = p->pid;
p->state = UNUSED; p->state = UNUSED;
p->pid = 0; p->pid = 0;
p->ppid = 0; p->parent = 0;
p->name[0] = 0; p->name[0] = 0;
release(&proc_table_lock); release(&proc_table_lock);
return pid; return pid;
......
...@@ -33,7 +33,7 @@ struct proc { ...@@ -33,7 +33,7 @@ struct proc {
char *kstack; // Bottom of kernel stack for this process char *kstack; // Bottom of kernel stack for this process
enum proc_state state; // Process state enum proc_state state; // Process state
int pid; // Process ID int pid; // Process ID
int ppid; // Parent pid struct proc *parent; // Parent process
void *chan; // If non-zero, sleeping on chan void *chan; // If non-zero, sleeping on chan
int killed; // If non-zero, have been killed int killed; // If non-zero, have been killed
struct file *ofile[NOFILE]; // Open files struct file *ofile[NOFILE]; // Open files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment