procTemp.c
int
fork(void)
{
  int i, pid;
  struct proc *np;
  struct proc *curproc = myproc();

  // Allocate process.
  if((np = allocproc()) == 0){
    return -1;
  }

  // Copy process state from proc.
  if((np->pgdir = copyuvm(curproc->pgdir, curproc->sz)) == 0){
    kfree(np->kstack);
    np->kstack = 0;
    np->state = UNUSED;
    return -1;
  }
  np->sz = curproc->sz;
  np->parent = curproc;
  *np->tf = *curproc->tf;
  np->tickets = curproc->tickets;  //PROJECT 1
  TICKETS+=np->tickets;
  // Clear %eax so that fork returns 0 in the child.
  np->tf->eax = 0;

  for(i = 0; i < NOFILE; i++)
    if(curproc->ofile[i])
      np->ofile[i] = filedup(curproc->ofile[i]);
  np->cwd = idup(curproc->cwd);

  safestrcpy(np->name, curproc->name, sizeof(curproc->name));

  pid = np->pid;

  acquire(&ptable.lock);

  np->state = RUNNABLE;

  release(&ptable.lock);

  return pid;
}
// Make sure that tickets are the same as the parent proceses PROJECT 1.
Make sure that tickets are the same as the parent proceses PROJECT 1.
Make sure that tickets are the same as the parent proceses PROJECT 1 .
int
fork(void)
{
  int i, pid;
  struct proc *np;
  struct proc *curproc = myproc();
  if((np = allocproc()) == 0){
    return -1;
  }
  if((np->pgdir = copyuvm(curproc->pgdir, curproc->sz)) == 0){
    kfree(np->kstack);
    np->kstack = 0;
    np->state = UNUSED;
    return -1;
  }
  np->sz = curproc->sz;
  np->parent = curproc;
  *np->tf = *curproc->tf;
  np->tickets = curproc->tickets;  
  TICKETS+=np->tickets;
  np->tf->eax = 0;
  for(i = 0; i < NOFILE; i++)
    if(curproc->ofile[i])
      np->ofile[i] = filedup(curproc->ofile[i]);
  np->cwd = idup(curproc->cwd);
  safestrcpy(np->name, curproc->name, sizeof(curproc->name));
  pid = np->pid;
  acquire(&ptable.lock);
  np->state = RUNNABLE;
  release(&ptable.lock);
  return pid;
}
int fork ( void ) { int i , pid ; struct proc * np ; struct proc * curproc = myproc ( ) ; if ( ( np = allocproc ( ) ) == 0 ) { return -1 ; } if ( ( np -> pgdir = copyuvm ( curproc -> pgdir , curproc -> sz ) ) == 0 ) { kfree ( np -> kstack ) ; np -> kstack = 0 ; np -> state = UNUSED ; return -1 ; } np -> sz = curproc -> sz ; np -> parent = curproc ; * np -> tf = * curproc -> tf ; np -> tickets = curproc -> tickets ; TICKETS += np -> tickets ; np -> tf -> eax = 0 ; for ( i = 0 ; i < NOFILE ; i ++ ) if ( curproc -> ofile [ i ] ) np -> ofile [ i ] = filedup ( curproc -> ofile [ i ] ) ; np -> cwd = idup ( curproc -> cwd ) ; safestrcpy ( np -> name , curproc -> name , sizeof ( curproc -> name ) ) ; pid = np -> pid ; acquire ( & ptable . lock ) ; np -> state = RUNNABLE ; release ( & ptable . lock ) ; return pid ; }
Make sure that tickets are the same as the parent proceses PROJECT 1.
Make sure that tickets are the same as the parent proceses PROJECT 1 .
// Allocate process. // Copy process state from proc. //PROJECT 1 // Clear %eax so that fork returns 0 in the child.