// 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 *p; int fd; if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++) { if(proc->ofile[fd]) { fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } begin_op(); iput(proc->cwd); end_op(); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->parent == proc && p->is_thread == 1) { p->killed = 1; if(p->state == SLEEPING) { p->state = RUNNABLE; } } } for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->parent == proc) { if (p->state == ZOMBIE) { p->killed = 1; } join(p->pid); } } for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->parent == proc) { p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. proc->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. void exit(void) { struct proc *p; int fd; if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } iput(proc->cwd); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->pid == proc->pid && p->state != ZOMBIE){ //undead thread p->state = ZOMBIE; if(p->is_thread){//it is a thread if(p->parent->num_of_thread_child){ p->parent->num_of_thread_child--; } //no more childran if(!p->parent->num_of_thread_child){ wakeup1(p->parent->parent); } } else{//it is a proccees p->num_of_thread_child--; if(!p->num_of_thread_child){ wakeup1(p->parent); } } } else if(p->parent == proc && p->is_thread !=1){// a proccess child p->parent = initproc; if(p->state == ZOMBIE){ wakeup1(initproc); } } } // Jump into the scheduler, never to return. proc->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. void exit(void) { struct proc *p; int fd; if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } #ifndef SELECTION_NONE #ifdef VERBOSE_PRINT_TRUE char* state; if(proc->state >= 0 && proc->state < NELEM(states) && states[proc->state]) state = states[proc->state]; else state = "???"; print_proc_data(proc, state); cprintf("\n"); #endif free_proc_pgmd(proc,1); //remove swap file and pages metadata #endif begin_op(); iput(proc->cwd); end_op(); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc){ p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. proc->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. void exit(void) { struct proc *p; int fd; if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd] && proc->thread == 0){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } begin_op(); iput(proc->cwd); end_op(); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->thread == 1 && p->parent == proc){ p->killed = 1; if(p->state == SLEEPING) // Wake process from sleep if necessary p->state = RUNNABLE; release(&ptable.lock); join(p->pid); acquire(&ptable.lock); p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } else if(p->parent == proc){ p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. proc->state = ZOMBIE; sched(); panic("zombie exit"); }
void texit(void) { // struct proc *p; int fd; if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } iput(proc->cwd); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. // for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ // if(p->parent == proc){ // p->parent = initproc; // if(p->state == ZOMBIE) // wakeup1(initproc); // } // } // Jump into the scheduler, never to return. proc->state = ZOMBIE; sched(); panic("zombie exit"); }
void thread_exit(void* ret_val) { proc->ret_val=ret_val; if(is_main_thread(proc)) { // check if last running thread if(proc->tcount <= 1) { exit(); } else { // Wait for children to exit acquire(&ptable.lock); sleep(proc, &ptable.lock); release(&ptable.lock); exit(); } } // Normal thread exit acquire(&ptable.lock); //iput(proc->cwd); proc->parent->tcount--; proc->cwd = 0; // Parent might be sleeping in wait(). wakeup1(proc->parent); // Jump into the scheduler, never to return. proc->state = ZOMBIE; sched(); panic("thread zombie exit"); }
// Wake up all processes sleeping on chan. void wakeup(void *chan) { acquire(&proc_table_lock); wakeup1(chan); release(&proc_table_lock); }
// Wake up all processes sleeping on chan. void wakeup(void *chan) { acquire(&ptable.lock); wakeup1(chan); release(&ptable.lock); }
// 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 *p; int fd; if(proc == initproc) panic("init exiting"); // cprintf("pid: %d is exiting\n",proc->pid); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } // part 2 int j; for(j=0 ; j < 200 ; j++) unlockInodesTable[proc->pid][j] = 0; iput(proc->cwd); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc){ p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. proc->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. void exit(void) { struct proc *p; int fd; if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } iput(proc->cwd); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc){ p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. proc->state = ZOMBIE; //**** remove--this may be unneccessary //cprintf("remove in exit\n"); removefromq(proc); //**** sched(); panic("zombie exit"); }
// Wake up all processes sleeping on chan. void wakeup(void *chan) { //acquire(&inswapper_lk); acquire(&ptable.lock); wakeup1(chan); release(&ptable.lock); //release(&inswapper_lk); }
// Wake up all processes sleeping on chan. void wakeup(void *chan) { acquire(&ptable.lock); // acquire(&runqueue.lock); wakeup1(chan); // release(&runqueue.lock); release(&ptable.lock); }
// 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 *p; int fd; cprintf("Exiting process. System free pages is %d, replacement count is %d\n",kfreepagecount(),replacementcount()); if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } begin_op(); iput(proc->cwd); end_op(); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc){ p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. proc->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. 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. 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. void exit(void) { struct proc *p; int fd; int i; for(i = 0; i < 22; i++) proc->count[i]=0; // set counts to 0s after termination if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } iput(proc->cwd); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc){ p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. proc->state = ZOMBIE; sched(); panic("zombie exit"); }
void twakeup(int tid){ struct proc *p; acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->state == SLEEPING && p->pid == tid && p->isthread == 1){ wakeup1(p); } } release(&ptable.lock); }
// Exit the current process. Does not return. // Exited processes remain in the zombie state // until their parent calls wait() to find out they exited. void exit(void) { struct proc *p; int fd; if(cp == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(cp->ofile[fd]){ fileclose(cp->ofile[fd]); cp->ofile[fd] = 0; } } iput(cp->cwd); cp->cwd = 0; acquire(&proc_table_lock); // Parent might be sleeping in wait(). wakeup1(cp->parent); // Pass abandoned children to init. for(p = proc; p < &proc[NPROC]; p++){ if(p->parent == cp){ p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. cp->killed = 0; setstate(cp, ZOMBIE); sched(); panic("zombie exit"); }
void cv_wake(int pid) { struct proc* p; acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->pid == pid) { wakeup1(p); break; } } release(&ptable.lock); }
int binary_semaphore_up(int binary_semaphore_ID){ acquire(&sem_table.sem_locks[binary_semaphore_ID]); struct binary_semaphore* sem = &sem_table.binary_semaphore[binary_semaphore_ID]; if(sem->initialize){ struct proc *p; struct proc* next = 0; //looking for whom to wakeup who are sleeping and next acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p != proc && p->wait_for_sem == binary_semaphore_ID){ p->sem_queue_pos--; if(p->sem_queue_pos == 0) next = p; } } if(sem->waiting>0){ sem->waiting--; } sem->value = 1;//sem is available //wake up the next thread if(next && next->state == SLEEPING) next->state = RUNNABLE; release(&ptable.lock); release(&sem_table.sem_locks[binary_semaphore_ID]);//realsing the sem wakeup1(sem); return 0; } else{ release(&sem_table.sem_locks[binary_semaphore_ID]);//realsing the sem cprintf("we had problem at binary_semaphore_up: the semaphore wasn't initialize\n"); return -1; } }
void thread_exit(void * ret_val){ acquire(&ptable.lock); if(proc->is_thread){//not the main procces if(proc->parent->num_of_thread_child==1){//the main thread already thread_exit and also all other thread proc->parent->num_of_thread_child--; release(&ptable.lock); exit(); } //this is not the last thread by any mean proc->ret_val = ret_val; // not main thread and not the last one proc->parent->num_of_thread_child--; proc->state = ZOMBIE; if(proc->thread_joined){ wakeup1(proc); } sched(); release(&ptable.lock); } else if (proc->num_of_thread_child == 1){//this is the main thread and it is the last thread proc->num_of_thread_child--; release(&ptable.lock); exit(); } else{//this is the main thread but other thread are alive proc->num_of_thread_child--; proc->state = ZOMBIE; sched(); release(&ptable.lock); } }
void kthread_exit() { struct proc *p; int threadsCounter=0; acquire(&ptable.lock); if(proc == initproc) panic("init exiting"); int i=0; for(;i<64;i++) { if(proc->sleepingThreads[i]!=0) wakeup1(proc->sleepingThreads[i]); } for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->pid==proc->pid && p->state!=ZOMBIE && p->state!=UNUSED) { threadsCounter++; } } if(threadsCounter==1) { for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) if(p->state == ZOMBIE && p->pid ==proc->pid && proc->threadId != p->threadId){ kfree(p->kstack); p->kstack = 0; p->state = UNUSED; p->pid = 0; p->parent = 0; p->name[0] = 0; p->killed = 0; } release(&ptable.lock); New_exit(); return ; } // Jump into the scheduler, never to return. proc->state = ZOMBIE; sched(); panic("zombie exit"); }
// TODO(byan23): Set inuse[] to 0? // 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) { //cprintf("exit pid: %d.\n", proc->pid); struct proc *p; int fd; if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } iput(proc->cwd); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc){ p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } // Jump into the scheduler, never to return. proc->state = ZOMBIE; int slot_no; for (slot_no = 0; slot_no < NPROC; ++slot_no) { if (&ptable.proc[slot_no] == proc) break; } //cprintf("found at slot: %d\n", slot_no); int pri = proc_stat.priority[slot_no]; switch(pri) { case 0: remove_from_queue(&q0_head, &q0_tail, proc); break; case 1: remove_from_queue(&q1_head, &q1_tail, proc); break; case 2: remove_from_queue(&q2_head, &q2_tail, proc); break; case 3: remove_from_queue(&q3_head, &q3_tail, proc); break; default: cprintf("Wrong priority queue while exiting.\n"); } proc_stat.inuse[slot_no] = 0; 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. void exit(void) { struct proc *p; int fd; if(proc == initproc) panic("init exiting"); if(proc->isThread == 0) { acquire(&ptable.lock); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { //should only kill p if child of this proc and is a thread if(p->parent == proc && p->isThread == 1) { release(&ptable.lock); kill(p->pid); join(p->pid); acquire(&ptable.lock); } } release(&ptable.lock); } // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } iput(proc->cwd); proc->cwd = 0; acquire(&ptable.lock); // Parent might be sleeping in wait(). wakeup1(proc->parent); // Pass abandoned children to init. for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc) { if(p->isThread == 1) { release(&ptable.lock); kill(p->pid); join(p->pid); acquire(&ptable.lock); } else { p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } } // Jump into the scheduler, never to return. proc->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. void exit(void) { struct proc *p; int fd; // debug only struct proc* test = proc; if(test/*proc*/ == initproc) panic("init exiting"); acquire(&ptable.lock); // Close all open files. OG process only if(!proc->thread) { for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } } iput(proc->cwd); // decrement ref count if(!proc->thread) // only og process can wipe this out proc->cwd = 0; // Pass abandoned children to init, kill and join if thread for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->parent == proc) { if(p->thread) { // kill p->killed = 1; // Wake process from sleep if necessary. if(p->state == SLEEPING) p->state = RUNNABLE; join_logic(p->pid); } else { p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } } } // Parent might be sleeping in wait()/join(). wakeup1(proc->parent); // Jump into the scheduler, never to return. proc->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. void exit(void) { struct proc *p; int fd; int rmBrothers=0; if(!is_main_thread(proc)) { // Kill main thread proc->parent->killed=1; if(proc->parent->state==SLEEPING) proc->parent->state=RUNNABLE; //clear_thread(proc); rmBrothers=1; //return; } if(proc == initproc) panic("init exiting"); cprintf("#"); //release(&ptable.lock); if(!holding(&ptable.lock)) { cprintf("[ex%d]", proc->pid); acquire(&ptable.lock); } cprintf("%"); // Pass abandoned proc children to init & // kill all threads beneath (children who are not procs) for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->parent == proc) { if(is_main_thread(p) && rmBrothers==0) { p->parent = initproc; if(p->state == ZOMBIE) wakeup1(initproc); } else { clear_thread(p); } } } if(rmBrothers) goto end; // Close all open files. for(fd = 0; fd < NOFILE; fd++) { if(proc->ofile[fd]) { fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } iput(proc->cwd); proc->cwd = 0; end: // Parent might be sleeping in wait(). wakeup1(proc->parent); // Jump into the scheduler, never to return. proc->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. void exit(void) { struct proc *p; int fd; if(proc == initproc) panic("init exiting"); // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(proc->ofile[fd]){ fileclose(proc->ofile[fd]); proc->ofile[fd] = 0; } } iput(proc->cwd); proc->cwd = 0; acquire(&ptable.lock); //cprintf("Lock acquired in exit\n"); // Parent might be sleeping in wait(). // //wakeup1(proc->parent); //cprintf("Wakeup the parent\n"); //acquire(&ptable.lock); // Pass abandoned children to init. //if(proc->isThread==0) if(proc->isThread==0) { for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc && p->isThread==1) { /* cprintf("parent will kill children\n"); release(&ptable.lock); cprintf("Lock released in exit\n"); kill(p->pid); acquire(&ptable.lock); cprintf("Thread killed in exit\n"); join(p->pid); cprintf("Wait over for killed thread in exit\n"); acquire(&ptable.lock); cprintf("Lock acquired in exit for loop\n"); */ p->killed = 1; // Wake process from sleep if necessary. if(p->state == SLEEPING) p->state = RUNNABLE; while(p->state!=ZOMBIE){ sleep(proc,&ptable.lock); } //cprintf("Calling join\n"); kfree(p->kstack); p->kstack = 0; // freevm(p->pgdir); p->state = UNUSED; p->pid = 0; p->parent = 0; p->name[0] = 0; p->killed = 0; /*release(&ptable.lock); join(p->pid); acquire(&ptable.lock); */ continue; } } } wakeup1(proc->parent); if(proc->isThread==0) { for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ if(p->parent == proc && p->isThread==0){ cprintf("Dealing with children process\n"); p->parent = initproc; if(p->state == ZOMBIE) { wakeup1(initproc); } } } } // Jump into the scheduler, never to return. proc->state = ZOMBIE; // cprintf("Calling schedule\n"); sched(); //release(&ptable.lock); //cprintf("LOck released finally"); panic("zombie exit"); }