int main(int argc, char *argv[]) { if (argc == 8 || argc == 3) { if ( PCB_Init(argc, argv) == ERROR ) return EXIT_SUCCESS; } else { return EXIT_FAILURE; } while ( 1 ) { /*TODO: Este codigo hay que habilitarlo en el momento de ejecutar el programa*/ if( PCB.nIdProcesoPadre == _ID_ACR_ ) { PCB.m_socketACR->onTimeOut= PCB_ExecuteProgram; PCB.m_socketACR->segundos_timeout = ALRM_T; }else{ PCB.m_socketADP->onTimeOut= PCB_ExecuteProgram; PCB.m_socketADP->segundos_timeout = ALRM_T; /*PCB.m_socketADP->onClose = PCB_VolverAlACR;*/ } conexiones_aguardarConexion( PCB.m_ListaSockets, &(PCB.m_ultimoSocket) ); } return EXIT_SUCCESS; }
void DoSpoon(UserContext *context) { // Get an available process id. int newPid = pidCount++; PCB *child = (PCB *)malloc(sizeof(PCB)); // If for any reason we can't fork, return ERROR to calling process. if (!newPid || !child) { context->regs[0] = ERROR; return; } PCB_Init(child); child->id = newPid; child->parent = current_process; queuePush(child->parent->children, child); if (queueIsEmpty(child->parent->children)) TracePrintf(3, "DoSpoon: parent queue empty.\n"); child->status = RUNNING; // Return 0 to child and arm the child for execution. child->user_context = *context; queuePush(ready_queue, child); queuePush(process_queue, child); KernelContextSwitch(SpoonKernel, current_process, child); // Return child's pid to parent and resume execution of the parent. if (current_process->id == newPid) { *context = current_process->user_context; context->regs[0] = 0; } else { context->regs[0] = newPid; } }