00001 00008 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00009 00010 #include <kernel.h> 00011 #include <proc.h> 00012 #include <queue.h> 00013 #include <semaphore.h> 00014 #include <memory.h> 00015 00016 extern void xdone(void); 00017 00018 /* 00019 * kill -- kill a process and remove it from the system 00020 */ 00021 syscall kill(int pid) 00022 { 00023 irqmask ps; 00024 pcb *ppcb; /* points to process control block for pid */ 00025 00026 if ( isbadpid(pid) || (0 == pid) 00027 || (PRFREE == (ppcb = &proctab[pid])->state) ) 00028 { return SYSERR; } 00029 ps = disable(); 00030 if (isbadpid(pid)) 00031 { 00032 restore(ps); 00033 return SYSERR; 00034 } 00035 ppcb = &proctab[pid]; 00036 00037 --numproc; 00038 00039 send(ppcb->parent, pid, BLOCK); 00040 00041 freemem(ppcb->stkbase); 00042 00043 switch (ppcb->state) 00044 { 00045 case PRCURR: 00046 ppcb->state = PRFREE; /* suicide */ 00047 resched(); 00048 00049 case PRWAIT: 00050 semtab[ppcb->sem].count++; 00051 00052 case PRSLEEP: 00053 case PRREADY: 00054 remove(pid); 00055 00056 default: 00057 ppcb->state = PRFREE; 00058 } 00059 00060 restore(ps); 00061 return OK; 00062 }