proc.c
void
exit(void)
{
  struct proc *curproc = myproc();
  struct proc *p;
  int fd;

  if(curproc == initproc)
    panic("init exiting");

  // Close all open files.
  for(fd = 0; fd < NOFILE; fd++){
    if(curproc->ofile[fd]){
      fileclose(curproc->ofile[fd]);
      curproc->ofile[fd] = 0;
    }
  }

  begin_op();
  iput(curproc->cwd);
  end_op();
  curproc->cwd = 0;

  acquire(&ptable.lock);

  // Parent might be sleeping in wait().
  wakeup1(curproc->parent);

  // Pass abandoned children to init.
  for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
    if(p->parent == curproc){
      p->parent = initproc;
      if(p->state == ZOMBIE)
        wakeup1(initproc);
    }
  }

  // Jump into the scheduler, never to return.
  /////alt
  curproc->terminationTime=ticks;
  /////alt
  curproc->state = ZOMBIE;
  sched();
  panic("zombie exit");
}
// Exit the current process.  Does not return.
// An exited process remains in the zombie state
// until its parent calls wait() to find out it exited.
Exit the current process.  Does not return.
An exited process remains in the zombie state
until its parent calls wait() to find out it exited.
Exit the current process . Does not return . An exited process remains in the zombie state until its parent calls wait () to find out it exited .
void
exit(void)
{
  struct proc *curproc = myproc();
  struct proc *p;
  int fd;
  if(curproc == initproc)
    panic("init exiting");
  for(fd = 0; fd < NOFILE; fd++){
    if(curproc->ofile[fd]){
      fileclose(curproc->ofile[fd]);
      curproc->ofile[fd] = 0;
    }
  }
  begin_op();
  iput(curproc->cwd);
  end_op();
  curproc->cwd = 0;
  acquire(&ptable.lock);
  wakeup1(curproc->parent);
  for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
    if(p->parent == curproc){
      p->parent = initproc;
      if(p->state == ZOMBIE)
        wakeup1(initproc);
    }
  }
  curproc->terminationTime=ticks;
  curproc->state = ZOMBIE;
  sched();
  panic("zombie exit");
}
void exit ( void ) { struct proc * curproc = myproc ( ) ; struct proc * p ; int fd ; if ( curproc == initproc ) panic ( " " ) ; for ( fd = 0 ; fd < NOFILE ; fd ++ ) { if ( curproc -> ofile [ fd ] ) { fileclose ( curproc -> ofile [ fd ] ) ; curproc -> ofile [ fd ] = 0 ; } } begin_op ( ) ; iput ( curproc -> cwd ) ; end_op ( ) ; curproc -> cwd = 0 ; acquire ( & ptable . lock ) ; wakeup1 ( curproc -> parent ) ; for ( p = ptable . proc ; p < & ptable . proc [ NPROC ] ; p ++ ) { if ( p -> parent == curproc ) { p -> parent = initproc ; if ( p -> state == ZOMBIE ) wakeup1 ( initproc ) ; } } curproc -> terminationTime = ticks ; curproc -> state = ZOMBIE ; sched ( ) ; panic ( " " ) ; }
Exit the current process.
Exit the current process .
// Close all open files. // Parent might be sleeping in wait(). // Pass abandoned children to init. // Jump into the scheduler, never to return. /////alt /////alt