int sys_exec(char* filename) { tid_t tid = process_execute(filename); if(tid == -1) // process execute failed, return -1 return -1; else // tid is valid { intr_disable(); thread_block(); // block myself, until child wakes me up // with the exec_status, telling me if the elf load was successful intr_enable(); struct thread* child = get_thread_from_tid(tid); if(child) { // exec_status will be -1 if load failed, hence we return -1 // in such case tid = child->exec_status; child->parent_waiting_exec = 0; // child had blocked itself, unblock it thread_unblock(child); } return tid; } }
/* handle a SIGCHLD signal */ void sigchld_callback(void) { int pid, status; for (;;) { if (!(pid = waitpid( -1, &status, WUNTRACED | WNOHANG | __WALL ))) break; if (pid != -1) { struct thread *thread = get_thread_from_tid( pid ); if (!thread) thread = get_thread_from_pid( pid ); handle_child_status( thread, pid, status, -1 ); } else break; } }