proc.c
int
kill(int pid)
{
  struct proc *p;

  acquire(&ptable.lock);
  for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
    if(p->pid == pid){
      p->killed = 1;
      // Wake process from sleep if necessary.
      if(p->state == SLEEPING){
        p->state = RUNNABLE;
      }
      release(&ptable.lock);
      return 0;
    }
  }
  release(&ptable.lock);
  return -1;
}
// Kill the process with the given pid.
// Process won't exit until it returns
// to user space (see trap in trap.c).
Kill the process with the given pid.
Process won't exit until it returns
to user space .
Kill the process with the given pid . Process won ' t exit until it returns to user space .
int
kill(int pid)
{
  struct proc *p;
  acquire(&ptable.lock);
  for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
    if(p->pid == pid){
      p->killed = 1;
      if(p->state == SLEEPING){
        p->state = RUNNABLE;
      }
      release(&ptable.lock);
      return 0;
    }
  }
  release(&ptable.lock);
  return -1;
}
int kill ( int pid ) { struct proc * p ; acquire ( & ptable . lock ) ; for ( p = ptable . proc ; p < & ptable . proc [ NPROC ] ; p ++ ) { if ( p -> pid == pid ) { p -> killed = 1 ; if ( p -> state == SLEEPING ) { p -> state = RUNNABLE ; } release ( & ptable . lock ) ; return 0 ; } } release ( & ptable . lock ) ; return -1 ; }
Kill the process with the given pid.
Kill the process with the given pid .
// Wake process from sleep if necessary.