summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-23 14:35:28 +0000
committerrsc <rsc>2007-08-23 14:35:28 +0000
commit3a057d12aed586b01d808d55a8b4c700523bbd95 (patch)
tree3faa54580b9bc5c8ecb133f6da06544224788052
parent1d7839a1daab5ebc37c4be4eded849714ff8f329 (diff)
downloadxv6-labs-3a057d12aed586b01d808d55a8b4c700523bbd95.tar.gz
xv6-labs-3a057d12aed586b01d808d55a8b4c700523bbd95.tar.bz2
xv6-labs-3a057d12aed586b01d808d55a8b4c700523bbd95.zip
avoid hardcoding init as pid 1 proc[0]
-rw-r--r--proc.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/proc.c b/proc.c
index d00be89..79fb702 100644
--- a/proc.c
+++ b/proc.c
@@ -11,6 +11,8 @@ struct spinlock proc_table_lock;
struct proc proc[NPROC];
struct proc *curproc[NCPU];
+static struct proc *initproc;
+
int nextpid = 1;
extern void forkret(void);
extern void forkret1(struct trapframe*);
@@ -162,7 +164,7 @@ userinit(void)
p->tf->eflags = FL_IF;
p->tf->esp = p->sz;
- // Push dummy return address to placate gcc.
+ // Make return address readable; needed for some gcc.
p->tf->esp -= 4;
*(uint*)(p->mem + p->tf->esp) = 0xefefefef;
@@ -170,6 +172,8 @@ userinit(void)
memmove(p->mem, _binary_initcode_start, (int)_binary_initcode_size);
safestrcpy(p->name, "initcode", sizeof(p->name));
p->state = RUNNABLE;
+
+ initproc = p;
}
//PAGEBREAK: 42
@@ -346,7 +350,7 @@ proc_exit(void)
struct proc *p;
int fd;
- if(cp->pid == 1)
+ if(cp == initproc)
panic("init exiting");
// Close all open files.
@@ -362,17 +366,19 @@ proc_exit(void)
acquire(&proc_table_lock);
- // Wake up our parent.
+ // Wake up waiting parent.
for(p = proc; p < &proc[NPROC]; p++)
if(p->pid == cp->ppid)
wakeup1(p);
- // Reparent our children to process 1.
- for(p = proc; p < &proc[NPROC]; p++)
+ // Pass abandoned children to init.
+ for(p = proc; p < &proc[NPROC]; p++){
if(p->ppid == cp->pid){
- p->ppid = 1;
- wakeup1(&proc[1]); // init
+ p->ppid = initproc->pid;
+ if(p->state == ZOMBIE)
+ wakeup1(initproc);
}
+ }
// Jump into the scheduler, never to return.
cp->killed = 0;