| plan 9 kernel history: overview | file list | diff list |
1990/03081/port/proc.c (diff list | history)
| 1990/03013/sys/src/9/port/proc.c:165,170 – 1990/03081/sys/src/9/port/proc.c:165,172 (short | long | prev | next) | ||
|
Use c to as current process instead of u->p. Add explicit process hierarchy a la Unix.
rsc Mon Mar 20 17:13:58 2006 | ||
| 1990/0227 | unlock(&procalloc); p->mach = 0; p->qnext = 0; | |
| 1990/03081 | p->kid = 0; p->sib = 0; | |
| 1990/0227 | p->nchild = 0; p->child = 0; p->exiting = 0; | |
| 1990/03013/sys/src/9/port/proc.c:339,351 – 1990/03081/sys/src/9/port/proc.c:341,354 | ||
| 1990/0227 | { char status[64]; ulong mypid; | |
| 1990/03081 | Proc *p, *c, *k, *l; | |
| 1990/0227 | Waitmsg w; int n; | |
| 1990/03081 | Chan *ch; | |
| 1990/0227 | ulong *up, *ucp, *wp; | |
| 1990/03081 | c = u->p; mypid = c->pid; | |
| 1990/0227 | if(s) strcpy(status, s); else | |
| 1990/03013/sys/src/9/port/proc.c:352,403 – 1990/03081/sys/src/9/port/proc.c:355,406 | ||
| 1990/0227 | status[0] = 0; if(freemem){ freesegs(-1); | |
| 1990/03081 | closepgrp(c->pgrp); | |
| 1990/0227 | close(u->dot); } for(n=0; n<=u->maxfd; n++) | |
| 1990/03081 | if(ch = u->fd[n]) /* assign = */ close(ch); | |
| 1990/0227 | /* * Any of my children exiting? */ | |
| 1990/03081 | while(c->nchild){ lock(&c->wait.queue); if(canlock(&c->wait.use)){ /* no child is exiting */ c->exiting = 1; unlock(&c->wait.use); unlock(&c->wait.queue); | |
| 1990/0227 | break; }else{ /* must wait for child */ | |
| 1990/03081 | unlock(&c->wait.queue); | |
| 1990/0227 | pwait(0); } } | |
| 1990/03081 | c->time[TReal] = MACHP(0)->ticks - c->time[TReal]; | |
| 1990/0227 | /* * Tell my parent */ | |
| 1990/03081 | p = c->parent; | |
| 1990/0227 | if(p == 0) goto out; qlock(&p->wait); lock(&p->wait.queue); | |
| 1990/03081 | if(p->pid==c->parentpid && !p->exiting){ | |
| 1990/0227 | w.pid = mypid; strcpy(w.msg, status); wp = &w.time[TUser]; | |
| 1990/03081 | up = &c->time[TUser]; ucp = &c->time[TCUser]; | |
| 1990/0227 | *wp++ = (*up++ + *ucp++)*MS2HZ; *wp++ = (*up++ + *ucp )*MS2HZ; *wp = (*up )*MS2HZ; | |
| 1990/03081 | p->child = c; | |
| 1990/0227 | /* * Pass info through back door, to avoid huge Proc's */ | |
| 1990/03081 | p->waitmsg = (Waitmsg*)(c->upage->pa|(((ulong)&w)&(BY2PG-1))|KZERO); c->state = Exiting; | |
| 1990/0227 | if(p->state == Inwait) ready(p); unlock(&p->wait.queue); | |
| 1990/03013/sys/src/9/port/proc.c:408,422 – 1990/03081/sys/src/9/port/proc.c:411,471 | ||
| 1990/0227 | } out: if(!freemem){ | |
| 1990/03081 | c->state = Broken; | |
| 1990/0227 | sched(); /* until someone lets us go */ freesegs(-1); | |
| 1990/03081 | closepgrp(c->pgrp); | |
| 1990/0227 | close(u->dot); } | |
| 1990/03081 | /* * Rearrange inheritance hierarchy * 1. my children's pop is now my pop */ lock(&c->kidlock); p = c->pop; if(k = c->kid) /* assign = */ do{ k->pop = p; k = k->sib; }while(k != c->kid); /* * 2. cut me from pop's tree */ if(p == 0) /* init process only; fix pops */ goto done; lock(&p->kidlock); k = p->kid; while(k->sib != c) k = k->sib; if(k == c) p->kid = 0; else{ if(p->kid == c) p->kid = c->sib; k->sib = c->sib; } /* * 3. pass my children (pop's grandchildren) to pop */ if(k = c->kid){ /* assign = */ if(p->kid == 0) p->kid = k; else{ l = k->sib; k->sib = p->kid->sib; p->kid->sib = l; } } unlock(&p->kidlock); done: unlock(&c->kidlock); | |
| 1990/0227 | lock(&procalloc); /* sched() can't do this */ | |
| 1990/03081 | lock(&c->debug); /* sched() can't do this */ c->state = Moribund; | |
| 1990/0227 | sched(); /* never returns */ } | |