Exemplo n.º 1
0
int main(void)
{
	int index;
	get_proc_pid();
	for (index = 0; index < pid_many; index++)
	{
		printf("pid_array[%d] = %d\n",index,pid_array[index]);
	}
}
Exemplo n.º 2
0
int sys_waitpid(pid_t pid, userptr_t status, int options, int *retval) {
    (void) options;
    int result;

    /* Arguments Error Handling */

    struct proc* waitproc = get_proc_pid(pid);
    if(waitproc == NULL) {
        return ESRCH;
    }
    // check if status pointer is aligned by 4 bytes
    if((uintptr_t)(const void *)(status) % 4 != 0) {
        return EFAULT;
    }

    // check for badflags
    if(options != 0) {
        return EINVAL;
    }

    if(pid == curthread->t_proc->pid || pid == curthread->t_proc->ppid) {
        return ECHILD;
    }

    if(curthread->t_proc->pid != waitproc->ppid) {
        return ECHILD;
    }
    
    if(waitproc->exited == false)
        P(waitproc->p_exitsem);
    if((int *) status != NULL) {
        result = copyout((const void *) &(waitproc->exitcode), status, sizeof(int));
        if(result)
            //V(waitproc->p_exitsem);
            return EFAULT;
    }
    dealloc_pid(waitproc);
//    kprintf("********************** destroying process - %d \n", dealloc_pid(waitproc));
    proc_destroy(waitproc);
    *retval = pid;
    return 0;
}