Beispiel #1
0
pid_t
sys_waitpid(pid_t pid, int * status, int options, int *retval){

	int result = valid_pid(pid);
	
	if(result){
		return result;
	}
	//If there is an option attached, FAIL. NO OPTIONS FOR YOU
	else if(options != 0){
		return EINVAL;
	}
	//If pointer is not aligned, throw an error. NO EXIT CODE FOR YOU
	else if((int)status%4 != 0){
		return EFAULT;
	}
	acquire_lock(pid);
	//While the process has not exited yet,  
	while(has_exit_code(pid) == false){
		put_to_sleep(pid);
	}
	
	*status = _MKWAIT_EXIT(get_exit_code(pid));
	release_lock(pid);
	release_pid(pid);
	*retval = pid;
	return 0;
}
Beispiel #2
0
void
process_destroy(pid_t pid)
{
	bool manageLock = processtable_biglock_do_i_hold();
	if(manageLock == false)
	{
		processtable_biglock_acquire();
	}

	KASSERT(processtable_biglock_do_i_hold());
	struct process *process = get_process(pid);
	release_pid(pid);
	kfree(process->p_name);
	// lock_destroy(process->p_waitlock);
	sem_destroy(process->p_waitsem);
	// sem_destroy(process->p_forksem);
	// cv_destroy(process->p_waitcv);
	//processlist_cleanup(&process->p_waiters);
	kfree(process);
	int num = (int) pid;
	processtable[num] = NULL;
	parentprocesslist[pid] = -1;

	if(manageLock == false)
	{
		processtable_biglock_release();
	}
	// kprintf("Cleaning process%d\n",pid);
}