/* * This file implements task waiting. A task may wait for another task to * change state. While waiting, the current task is blocked. When the target * process changes state the current task is unblocked and gets any relevant * information from it before releasing it. */ #include #include /* Wait for a child process to change state */ pid_t waitpid(pid_t pid, int *wstatus, int options) { if (wstatus && !verify_access(wstatus, sizeof(int), PROT_WRITE)) return -EFAULT; Task *task = find_task(pid); if (!task) return -ECHILD; current->target = get(task); if (task->state != TERMINATED) { if (!task->wait) task->wait = create_list(&taskType, LIST_NORMAL); block_task(WAITING, task->wait); } if (wstatus) *wstatus = task->status; put(current->target); current->target = NULL; return task->tid; }