/* * Wait for a process to exit. * Params: * state->ebx - pid of process to wait for * Returns: the exit code of the process, * or error code (< 0) on error */ static int Sys_Wait(struct Interrupt_State* state) { int exitcode; Enable_Interrupts(); exitcode = Join(Lookup_Thread(state->ebx, 1)); // weak; Disable_Interrupts(); return exitcode; //TODO("Wait system call"); }
/* * Send a signal to a process * Params: * state->ebx - pid of process to send signal to * state->ecx - signal number * Returns: 0 on success or error code (< 0) on error */ static int Sys_Kill(struct Interrupt_State* state) { struct Kernel_Thread* kthread = NULL; kthread = Lookup_Thread(state->ebx, false); Send_Signal(kthread, state->ecx); if(kthread->blocked == true){ Wake_Up_Process(kthread); } if(Get_Current()->pid != kthread->owner) kthread->refCount-- ; /* deref */ return 0; }
/* * Wait for a process to exit. * Params: * state->ebx - pid of process to wait for * Returns: the exit code of the process, * or error code (< 0) on error */ static int Sys_Wait(struct Interrupt_State *state) { int exitCode; struct Kernel_Thread *kthread = Lookup_Thread(state->ebx, 0); if (kthread == 0) return -12; Enable_Interrupts(); exitCode = Join(kthread); Disable_Interrupts(); return exitCode; }
/* * Wait for a process to exit. * Params: * state->ebx - pid of process to wait for * Returns: the exit code of the process, * or error code (< 0) on error */ static int Sys_Wait(struct Interrupt_State* state) { int exit_code; struct Kernel_Thread *kthread=Lookup_Thread((int)state->ebx); if(kthread==NULL)return -1; Enable_Interrupts(); exit_code = Join(kthread); Disable_Interrupts(); return exit_code; }
/* * Wake up a single thread waiting on given wait queue * (if there are any threads waiting). Chooses the highest priority thread. * Interrupts must be disabled! */ void Wake_Up_Thread(struct Thread_Queue* waitQueue, int pid) { struct Kernel_Thread* thread = Lookup_Thread(pid);; KASSERT(!Interrupts_Enabled()); if (thread != 0) { Remove_Thread(waitQueue, thread); Make_Runnable(thread); /*Print("Wake_Up_One: waking up %x from %x\n", best, g_currentThread); */ } }
/* * Send a signal to a process * Params: * state->ebx - pid of process to send signal to * state->ecx - signal number * Returns: 0 on success or error code (< 0) on error */ static int Sys_Kill(struct Interrupt_State *state) { struct Kernel_Thread *kthread = Lookup_Thread(state->ebx, 1); if (kthread == 0) return EINVALID; if (!IS_SIGNUM(state->ecx)) return EINVALID; if (kthread->userContext == 0) return EINVALID; Send_Signal(kthread, state->ecx); return 0; }
/* * Wait for a process to exit. * Params: * state->ebx - pid of process to wait for * Returns: the exit code of the process, * or error code (< 0) on error */ static int Sys_Wait(struct Interrupt_State* state) { int exit_code = -1; struct Kernel_Thread *kthread = Lookup_Thread(state->ebx); if (kthread==NULL){ Print("ERROR thred id not found\n"); return -1; } Enable_Interrupts(); exit_code = Join(kthread); Disable_Interrupts(); return exit_code; }