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,1701990/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,3511990/03081/sys/src/9/port/proc.c:341,354
1990/0227    
{ 
	char status[64]; 
	ulong mypid; 
	Proc *p; 
1990/03081    
	Proc *p, *c, *k, *l; 
1990/0227    
	Waitmsg w; 
	int n; 
	Chan *c; 
1990/03081    
	Chan *ch; 
1990/0227    
	ulong *up, *ucp, *wp; 
 
	mypid = u->p->pid; 
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,4031990/03081/sys/src/9/port/proc.c:355,406
1990/0227    
		status[0] = 0; 
	if(freemem){ 
		freesegs(-1); 
		closepgrp(u->p->pgrp); 
1990/03081    
		closepgrp(c->pgrp); 
1990/0227    
		close(u->dot); 
	} 
	for(n=0; n<=u->maxfd; n++) 
		if(c = u->fd[n])	/* assign = */ 
			close(c); 
1990/03081    
		if(ch = u->fd[n])	/* assign = */ 
			close(ch); 
1990/0227    
	/* 
	 * Any of my children exiting? 
	 */ 
	while(u->p->nchild){ 
		lock(&u->p->wait.queue); 
		if(canlock(&u->p->wait.use)){	/* no child is exiting */ 
			u->p->exiting = 1; 
			unlock(&u->p->wait.use); 
			unlock(&u->p->wait.queue); 
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 */ 
			unlock(&u->p->wait.queue); 
1990/03081    
			unlock(&c->wait.queue); 
1990/0227    
			pwait(0); 
		} 
	} 
 
	u->p->time[TReal] = MACHP(0)->ticks - u->p->time[TReal]; 
	/* 
1990/03081    
	c->time[TReal] = MACHP(0)->ticks - c->time[TReal]; 
1990/0227    
	/* 
	 * Tell my parent 
	 */ 
	p = u->p->parent; 
1990/03081    
	p = c->parent; 
1990/0227    
	if(p == 0) 
		goto out; 
	qlock(&p->wait); 
	lock(&p->wait.queue); 
	if(p->pid==u->p->parentpid && !p->exiting){ 
1990/03081    
	if(p->pid==c->parentpid && !p->exiting){ 
1990/0227    
		w.pid = mypid; 
		strcpy(w.msg, status); 
		wp = &w.time[TUser]; 
		up = &u->p->time[TUser]; 
		ucp = &u->p->time[TCUser]; 
1990/03081    
		up = &c->time[TUser]; 
		ucp = &c->time[TCUser]; 
1990/0227    
		*wp++ = (*up++ + *ucp++)*MS2HZ; 
		*wp++ = (*up++ + *ucp  )*MS2HZ; 
		*wp   = (*up           )*MS2HZ; 
		p->child = u->p; 
1990/03081    
		p->child = c; 
1990/0227    
		/* 
		 * Pass info through back door, to avoid huge Proc's 
		 */ 
		p->waitmsg = (Waitmsg*)(u->p->upage->pa|(((ulong)&w)&(BY2PG-1))|KZERO); 
		u->p->state = Exiting; 
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,4221990/03081/sys/src/9/port/proc.c:411,471
1990/0227    
	} 
   out: 
	if(!freemem){ 
		u->p->state = Broken; 
1990/03081    
		c->state = Broken; 
1990/0227    
		sched();		/* until someone lets us go */ 
		freesegs(-1); 
		closepgrp(u->p->pgrp); 
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 */ 
	lock(&u->p->debug);	/* sched() can't do this */ 
	u->p->state = Moribund; 
1990/03081    
	lock(&c->debug);	/* sched() can't do this */ 
	c->state = Moribund; 
1990/0227    
	sched();	/* never returns */ 
} 
 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)