// Create a new process copying p as the parent. // Sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE. int fork(void) { int i, pid; struct proc *np; // Allocate process. if((np = allocproc()) == 0) return -1; // cprintf("Inside fork\n"); // cprintf("Fork: Process PID: %d\n",np->pid); // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); pid = np->pid; np->state = RUNNABLE; safestrcpy(np->name, proc->name, sizeof(proc->name)); // cprintf(">>>>>>>>>>>>>>>>>>>>>>>>Forked: Process name: [%s]\tPID: [%d]\tStack: [%d]\n",np->name,np->pid,np->stack); return pid; }
// Create a new process copying p as the parent. // Sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE. int fork(int Nt) { int i, pid; struct proc *np; // Allocate process. if((np = allocproc()) == 0) return -1; // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->cwd = idup(proc->cwd); pid = np->pid; receivetickets(np, Nt); //StartFinish(np, 0); //Show the process starts np->state = RUNNABLE; safestrcpy(np->name, proc->name, sizeof(proc->name)); return pid; }
// Create a new process copying p as the parent. // Sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE. int fork(void) { int i, pid; struct proc *np; // Allocate process. if((np = allocproc()) == 0) return -1; // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); pid = np->pid; np->state = RUNNABLE; np->priority = proc->priority; safestrcpy(np->name, proc->name, sizeof(proc->name)); acquire(&ptable.lock); add_to_ready(np); release(&ptable.lock); return pid; }
// Create a new process copying p as the parent. // Sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE. int fork(void) { int i, pid; struct proc *np; //cprintf("In fork...\n"); // Allocate process. if((np = allocproc()) == 0) return -1; // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz, proc->s_sz)) == 0){ // CHANGED kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->s_sz = proc->s_sz; // CHANGED np->parent = proc; *np->tf = *proc->tf; // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); pid = np->pid; np->state = RUNNABLE; safestrcpy(np->name, proc->name, sizeof(proc->name)); // cprintf("Exiting fork...\n"); return pid; }
// Create a new process copying p as the parent. // Sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE. int fork(void) { int i, pid; struct proc *np; // Allocate process. if((np = allocproc()) == 0) return -1; // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; /* np->shmem_size = proc->shmem_size; */ /* np->shmem_tok = proc->shmem_tok; */ /* np->startaddr = proc->startaddr; */ // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); pid = np->pid; np->state = RUNNABLE; safestrcpy(np->name, proc->name, sizeof(proc->name)); return pid; }
// Create a new process copying p as the parent. // Sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE. int fork(void) { int i, pid; struct proc *np; // Allocate process. if((np = allocproc()) == 0) return -1; // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0) { kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; memcpy(np->handlers, proc->handlers, 32); /* A&T - deep-copy the array of handlers from the parent. */ // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); pid = np->pid; np->state = RUNNABLE; safestrcpy(np->name, proc->name, sizeof(proc->name)); return pid; }
// Create a new process copying p as the parent. // Sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE. int fork(void) { int i, pid; struct proc *np; // Allocate process. if((np = allocproc()) == 0) return -1; // Copy process state from p. if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){ kfree(np->kstack); np->kstack = 0; np->state = UNUSED; return -1; } np->sz = proc->sz; np->parent = proc; *np->tf = *proc->tf; #ifndef SELECTION_NONE if (proc->pid > 2) // father is not shell or initproc { // copy from father copy_proc_pgmd(np, proc); } else if (np->pid > 2) // son is not shell { // create new create_proc_pgmd(np); } #endif // Clear %eax so that fork returns 0 in the child. np->tf->eax = 0; for(i = 0; i < NOFILE; i++) if(proc->ofile[i]) np->ofile[i] = filedup(proc->ofile[i]); np->cwd = idup(proc->cwd); safestrcpy(np->name, proc->name, sizeof(proc->name)); pid = np->pid; /* #ifndef SELECTION_NONE cprintf("inside fork\n"); if(pid > 2) { cprintf("fork: pid>2\n"); //create a new swap for sons of user init and shell create_proc_pgmd(np); } if(!ShellOrInit(proc->name)) { cprintf("not shell or init\n"); copy_proc_pgmd(np, proc); } #endif */ // lock to force the compiler to emit the np->state write last. acquire(&ptable.lock); np->state = RUNNABLE; release(&ptable.lock); return pid; }