home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / TS / SRC / KILL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-12  |  2.7 KB  |  96 lines

  1.                 /******************************************
  2.            *            KILL.C             *
  3.                * Copyright TimeSlice, Inc. 1985, 86, 87. *
  4.                ******************************************/
  5.  
  6.  
  7. #include <ts.h>
  8.  
  9. /***
  10. * KILL( PROC_PTR )
  11. * Terminates the specified process. 
  12. * Returns: -1 if process not found,
  13. *           0 if successful termination occurs.
  14. *       +1 if process's poisoined with KILL bit.
  15. ***/
  16. int kill( proc_ptr )
  17. PROCESS    *proc_ptr ;
  18. {
  19.   PROCESS *pp ;
  20.  
  21.   /*die right away if kill self*/
  22.   if( curproc == proc_ptr )
  23.     endself() ;
  24.  
  25.   /*we are going to manipulate lists, it is safer to put system to sleep*/
  26.   critstart( DOS_CRCLASS ) ;
  27.   ssleep() ;
  28.  
  29.   /*make sure process to kill is in process list*/
  30.   for( pp = curproc ; pp->nxt != curproc && pp->nxt != proc_ptr ; pp = pp->nxt );                        
  31.   if( pp->nxt != proc_ptr ) {        /*pro_ptr does not exist any longer*/
  32.     swake();
  33.     critend( DOS_CRCLASS );
  34.     return -1;
  35.   }
  36.  
  37.   /*if currently critical, simply set proc_ptr's KILL bit*/
  38.   if( proc_ptr->crlev || proc_ptr->chlev ) {
  39.     proc_ptr->status |= KILL ;
  40.     swake();
  41.     critend( DOS_CRCLASS );
  42.     return 1;
  43.   }
  44.  
  45.   /*now,we can kill proc_ptr: remove it from various lists*/
  46.   pp->nxt = proc_ptr->nxt;        /*remove from process list*/
  47.   if( -1 != proc_ptr->crwait ) {    /*remove from possible critbld list*/
  48.     CRCLASS *crcptr;
  49.     
  50.     crcptr = crit_tab + proc_ptr->crwait ;
  51.     if( crcptr->crblkd == proc_ptr ) {    /*in front of list*/
  52.       crcptr->crblkd = proc_ptr->crnxt;
  53. /*      crcptr->crblkd->status &= ~CRITWAIT; */
  54.     } else {                /*within list*/
  55.       for( pp = crcptr->crblkd ; pp->crnxt != proc_ptr ; pp = pp->crnxt );
  56.       pp->crnxt = proc_ptr->crnxt ;    /* take proc_ptr out of critical list*/
  57.     }
  58.   }
  59.  
  60.   /*remove it from possible chanwait list*/
  61.   if( (proc_ptr->status & CHANWAIT) || proc_ptr->chnxt ) {
  62.     CHAN *chptr;
  63.  
  64.     for( chptr = _chfrnt ;; chptr = chptr->nxt ) {
  65.       if( chptr->rf )
  66.         if( chptr->rf == proc_ptr ) {
  67.           chptr->rf = proc_ptr->chnxt;
  68.       chptr->rf->status &= ~CHANWAIT;
  69.       goto K_END;
  70.         } else
  71.           for( pp = chptr->rf ; pp->chnxt ; pp = pp->chnxt )
  72.         if( pp->chnxt == proc_ptr ) {
  73.           pp->chnxt = proc_ptr->chnxt;
  74.           goto K_END;
  75.         }
  76.       if( chptr->wf )
  77.         if( chptr->wf == proc_ptr ) {
  78.           chptr->wf = proc_ptr->chnxt;
  79.       chptr->wf->status &= ~CHANWAIT;
  80.       goto K_END;
  81.         } else
  82.           for( pp = chptr->wf ; pp->chnxt ; pp = pp->chnxt )
  83.         if( pp->chnxt == proc_ptr ) {
  84.           pp->chnxt = proc_ptr->chnxt;
  85.           goto K_END;
  86.         }
  87.     }
  88.   }
  89.  
  90. K_END:      
  91.   _ts_free( proc_ptr->name ) ;
  92.   swake() ;
  93.   critend( DOS_CRCLASS );
  94.   return 0;
  95. }
  96.