proc.c
int
wait(int * cpuBurst , int * turnaround , int * waiting)
{
  struct proc *p;
  int havekids, pid;
  struct proc *curproc = myproc();
 // int counter=0;
  acquire(&ptable.lock);
  for(;;){
    // Scan through table looking for exited children.
    havekids = 0;
    for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
      //counter++;
      if(p->parent != curproc)
        continue;
      havekids = 1;
      //cprintf("cbt before zombie %d",p->runningTime);
      if(p->state == ZOMBIE){

        if(policy == 1 || policy==2 || policy==3){
          
          *cpuBurst=p->runningTime;
          *turnaround=p->readyTime + p->sleepingTime + p->runningTime;
          *waiting=p->readyTime + p->sleepingTime;
        }
        // Found one.
       // cprintf("cbt after zombie %d",p->runningTime);
        pid = p->pid;
        kfree(p->kstack);
        p->kstack = 0;
        freevm(p->pgdir);
        p->pid = 0;
        p->parent = 0;
        p->name[0] = 0;
        p->killed = 0;
        p->runningTime=0;
        p->readyTime=0;
        p->sleepingTime=0;
        p->state = UNUSED;
        release(&ptable.lock);
          ////for multiLayeredScheduling
        
          if(multiLayeredFlag!=0)
            return p->queqeNumber;

          else{

            if(policy==2 || policy==3)
              return p->priority;

            if(policy==0 || policy==1)
              return pid;


          }

      }
    }

    // No point waiting if we don't have any children.
    if(!havekids || curproc->killed){
      release(&ptable.lock);
      return -1;
    }

    // Wait for children to exit.  (See wakeup1 call in proc_exit.)
    sleep(curproc, &ptable.lock);  //DOC: wait-sleep
  }
}
// Wait for a child process to exit and return its pid.
// Return -1 if this process has no children.
Wait for a child process to exit and return its pid.
Return -1 if this process has no children.
Wait for a child process to exit and return its pid . Return - 1 if this process has no children .
int
wait(int * cpuBurst , int * turnaround , int * waiting)
{
  struct proc *p;
  int havekids, pid;
  struct proc *curproc = myproc();
  acquire(&ptable.lock);
  for(;;){
    havekids = 0;
    for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
      if(p->parent != curproc)
        continue;
      havekids = 1;
      if(p->state == ZOMBIE){
        if(policy == 1 || policy==2 || policy==3){
          *cpuBurst=p->runningTime;
          *turnaround=p->readyTime + p->sleepingTime + p->runningTime;
          *waiting=p->readyTime + p->sleepingTime;
        }
        pid = p->pid;
        kfree(p->kstack);
        p->kstack = 0;
        freevm(p->pgdir);
        p->pid = 0;
        p->parent = 0;
        p->name[0] = 0;
        p->killed = 0;
        p->runningTime=0;
        p->readyTime=0;
        p->sleepingTime=0;
        p->state = UNUSED;
        release(&ptable.lock);
          if(multiLayeredFlag!=0)
            return p->queqeNumber;
          else{
            if(policy==2 || policy==3)
              return p->priority;
            if(policy==0 || policy==1)
              return pid;
          }
      }
    }
    if(!havekids || curproc->killed){
      release(&ptable.lock);
      return -1;
    }
    sleep(curproc, &ptable.lock);  
  }
}
int wait ( int * cpuBurst , int * turnaround , int * waiting ) { struct proc * p ; int havekids , pid ; struct proc * curproc = myproc ( ) ; acquire ( & ptable . lock ) ; for ( ; ; ) { havekids = 0 ; for ( p = ptable . proc ; p < & ptable . proc [ NPROC ] ; p ++ ) { if ( p -> parent != curproc ) continue ; havekids = 1 ; if ( p -> state == ZOMBIE ) { if ( policy == 1 || policy == 2 || policy == 3 ) { * cpuBurst = p -> runningTime ; * turnaround = p -> readyTime + p -> sleepingTime + p -> runningTime ; * waiting = p -> readyTime + p -> sleepingTime ; } pid = p -> pid ; kfree ( p -> kstack ) ; p -> kstack = 0 ; freevm ( p -> pgdir ) ; p -> pid = 0 ; p -> parent = 0 ; p -> name [ 0 ] = 0 ; p -> killed = 0 ; p -> runningTime = 0 ; p -> readyTime = 0 ; p -> sleepingTime = 0 ; p -> state = UNUSED ; release ( & ptable . lock ) ; if ( multiLayeredFlag != 0 ) return p -> queqeNumber ; else { if ( policy == 2 || policy == 3 ) return p -> priority ; if ( policy == 0 || policy == 1 ) return pid ; } } } if ( ! havekids || curproc -> killed ) { release ( & ptable . lock ) ; return -1 ; } sleep ( curproc , & ptable . lock ) ; } }
Wait for a child process to exit and return its pid.
Wait for a child process to exit and return its pid .
// int counter=0; // Scan through table looking for exited children. //counter++; //cprintf("cbt before zombie %d",p->runningTime); // Found one. // cprintf("cbt after zombie %d",p->runningTime); ////for multiLayeredScheduling // No point waiting if we don't have any children. // Wait for children to exit.  (See wakeup1 call in proc_exit.) //DOC: wait-sleep