home *** CD-ROM | disk | FTP | other *** search
- /******************************************
- * KILL.C *
- * Copyright TimeSlice, Inc. 1985, 86, 87. *
- ******************************************/
-
-
- #include <ts.h>
-
- /***
- * KILL( PROC_PTR )
- * Terminates the specified process.
- * Returns: -1 if process not found,
- * 0 if successful termination occurs.
- * +1 if process's poisoined with KILL bit.
- ***/
- int kill( proc_ptr )
- PROCESS *proc_ptr ;
- {
- PROCESS *pp ;
-
- /*die right away if kill self*/
- if( curproc == proc_ptr )
- endself() ;
-
- /*we are going to manipulate lists, it is safer to put system to sleep*/
- critstart( DOS_CRCLASS ) ;
- ssleep() ;
-
- /*make sure process to kill is in process list*/
- for( pp = curproc ; pp->nxt != curproc && pp->nxt != proc_ptr ; pp = pp->nxt );
- if( pp->nxt != proc_ptr ) { /*pro_ptr does not exist any longer*/
- swake();
- critend( DOS_CRCLASS );
- return -1;
- }
-
- /*if currently critical, simply set proc_ptr's KILL bit*/
- if( proc_ptr->crlev || proc_ptr->chlev ) {
- proc_ptr->status |= KILL ;
- swake();
- critend( DOS_CRCLASS );
- return 1;
- }
-
- /*now,we can kill proc_ptr: remove it from various lists*/
- pp->nxt = proc_ptr->nxt; /*remove from process list*/
- if( -1 != proc_ptr->crwait ) { /*remove from possible critbld list*/
- CRCLASS *crcptr;
-
- crcptr = crit_tab + proc_ptr->crwait ;
- if( crcptr->crblkd == proc_ptr ) { /*in front of list*/
- crcptr->crblkd = proc_ptr->crnxt;
- /* crcptr->crblkd->status &= ~CRITWAIT; */
- } else { /*within list*/
- for( pp = crcptr->crblkd ; pp->crnxt != proc_ptr ; pp = pp->crnxt );
- pp->crnxt = proc_ptr->crnxt ; /* take proc_ptr out of critical list*/
- }
- }
-
- /*remove it from possible chanwait list*/
- if( (proc_ptr->status & CHANWAIT) || proc_ptr->chnxt ) {
- CHAN *chptr;
-
- for( chptr = _chfrnt ;; chptr = chptr->nxt ) {
- if( chptr->rf )
- if( chptr->rf == proc_ptr ) {
- chptr->rf = proc_ptr->chnxt;
- chptr->rf->status &= ~CHANWAIT;
- goto K_END;
- } else
- for( pp = chptr->rf ; pp->chnxt ; pp = pp->chnxt )
- if( pp->chnxt == proc_ptr ) {
- pp->chnxt = proc_ptr->chnxt;
- goto K_END;
- }
- if( chptr->wf )
- if( chptr->wf == proc_ptr ) {
- chptr->wf = proc_ptr->chnxt;
- chptr->wf->status &= ~CHANWAIT;
- goto K_END;
- } else
- for( pp = chptr->wf ; pp->chnxt ; pp = pp->chnxt )
- if( pp->chnxt == proc_ptr ) {
- pp->chnxt = proc_ptr->chnxt;
- goto K_END;
- }
- }
- }
-
- K_END:
- _ts_free( proc_ptr->name ) ;
- swake() ;
- critend( DOS_CRCLASS );
- return 0;
- }
-