//Tester Function void QueueTest(){ createPCB("THisisPCB7", 0, 4); createPCB("THisisPCB4", 0, 3); createPCB("THisisPCB5", 0, 5); //createPCB("THisisPCB2", 0, 1); //DequeueName(readyQueue,"THisisPCB3"); printQueue(readyQueue); }
void createRandomPCB(FIFO_queue_p theList, int theNumberOfPCB) { char processNameSetUp[10] = "Process"; int PCBCounter = 0; int i = 0; PCB_p tempPCB; for (PCBCounter = 0; PCBCounter < theNumberOfPCB; PCBCounter++) { srand(time(NULL) * (PCBCounter + 1)); sprintf(processNameSetUp, "Process%d", PCBCounter); tempPCB = createPCB(processNameSetUp, PCBCounter, rand() % 4, 0, 0, ready); enqueue(theList, tempPCB); toString(tempPCB); strcpy(processNameSetUp, "Process"); //PCBCounter++; } //return theList; }
//Creates an IDLE PCB // returns the pointer to the list; NULL if list not created PCB_p createIdlePCB() { int i = 0; //struct control_block_type testing; PCB_p pcb = createPCB("IDLE_PCB", 0, 0, 0, 0, running); // if allocation was successful strcpy(pcb->name, "IDLE_PCB"); pcb->pid = -1; pcb->priority = 15; pcb->interrupt_simulator = 0; pcb->pc = 0; pcb->currentState = running; //New stuff //pcb->max_pc = ? jowy added (do we need a new parameter?) pcb->creation = getTheCurrentTime(); pcb->terminate = INT_MAX; pcb->term_count = 0; for (; i < 4; i++) { pcb->IO_1_traps[i] = -1; pcb->IO_2_traps[i] = -1; } return pcb; }
int PCB_Init(int argc, char *argv[] ) { do { Log_Inicializar( _PPCB_, "1" ); PCB.PPCB_ID = atol (argv[1]); PCB.tiempoRestanteOper = 0; /*Se inicializa en cero*/ PCB.argc = argc; /*Lo guardo para arreglar error en crear config.ppcb<ID>*/ /*tests*/ if (0) { createPCB(argv); createPCBConfig(); PCB_ImprimirInfoCtr(); return -1; } if ( argc == 3) { PCB.nIdProcesoPadre = atoi( argv[2] ); /*el proceso que lo origino (o _ID_ACR_ o _ID_ADP_)*/ if ( PCB_LeerConfig() == ERROR ) { Log_log( log_error, "Error leyendo la configuracion" ); break; } } else if ( argc == 8) { PCB.nIdProcesoPadre = _ID_ACR_; /*el unico que usa esta cant de param es el ACR*/ if ( createPCB(argv) == ERROR){ Log_log( log_error, "Error creando la configuracion" ); break; } } /* inicializacion de la lista de sockets */ if ( !(PCB.m_ListaSockets = malloc( MALLOC_SOCKS_INI *sizeof(tSocket*) ) ) ) return ERROR; memset( PCB.m_ListaSockets, 0, MALLOC_SOCKS_INI * sizeof(tSocket*) ); /*Creo el socket de escucha*/ /*PCB.m_ultimoSocket = SOCK_ESCUCHA; */ if ( argc == 8 ) { if ( PCB_ConectarConACR() == ERROR ) { Log_log( log_error, "No se pudo establecer conexion con el ACR" ); return ERROR; } /*tSocket* sockDummy = (tSocket*)CrearSocket(); sockDummy -> estado = estadoConn_standby; PCB.m_ListaSockets[SOCK_ADP] = sockDummy;*/ } if ( argc == 3 ) { if( PCB.nIdProcesoPadre == _ID_ACR_ ) /*si lo creo el ACR, se conecta con el ACR*/ { if ( PCB_ConectarConACR() == ERROR ) { Log_log( log_error, "No se pudo establecer conexion con el ACR" ); return ERROR; } /*tSocket* sockDummy = (tSocket*)CrearSocket(); sockDummy -> estado = estadoConn_standby; PCB.m_ListaSockets[SOCK_ADP] = sockDummy;*/ }else if( PCB.nIdProcesoPadre == _ID_ADP_ ) /*si lo creo el ADP, se conecta con el ADP*/ { if ( PCB_ConectarConADP() == ERROR ) { Log_log( log_error, "No se pudo establecer conexion con el ADP" ); return ERROR; } /*tSocket* sockDummy = (tSocket*)CrearSocket(); sockDummy -> estado = estadoConn_standby; PCB.m_ListaSockets[SOCK_ACR] = sockDummy;*/ } } signal(SIGALRM, PCB_ProcesarSeniales); signal(SIGCHLD, PCB_ProcesarSeniales); signal(SIGTERM, PCB_ProcesarSeniales); signal(SIGUSR1, PCB_ProcesarSeniales); signal(SIGUSR2, PCB_ProcesarSeniales); signal(SIGINT, PCB_ProcesarSeniales); /*PCB_Migrar("127.0.0.1",9550, SOCK_ADP); /* Esto fue de prueba*/ return OK; }while(0); if ( errno ) { Log_log( log_error, conn_getLastError() ); } else { printf("No se puede crear el Buscador: revise el archivo de configuracion\n"); } exit(EXIT_FAILURE); return ERROR; }
void main(void) { srand(time(NULL)); char processNameSetUp[10] = "Process"; int i = 0; FIFO_queue_p PCBContainer = createLinkedList(); PCB_p tempPCB; int PCBCounter = 0; int loopCounter = 0; int numberOfPCB = 0; FILE* outFile = fopen("scheduleTrace.txt", "w+"); fprintf(outFile, "Group 5: Nok Him Nam, Jowy Tran, Mark Johnson, David Humphreys\nDate (DD/MM/YY) : 28/ 01/ 2015\nAssignment : Problem 2 - Scheduling\n"); //Create CPU CPU_instance_p testingCPU = createCPU(); //Master CPU Loop while (loopCounter <= MAX_NUMBER_OF_RUNTIME) { if (loopCounter % PRINT_EVERY_xTIMES == 0) { fprintf(outFile, "\n__________NEXT TIME QUANTUM : %d___________\n", loopCounter); } numberOfPCB = rand() % 6; //While the number of PCBs created is less than 30, create more PCBs if (PCBCounter < MAX_NUMBER_OF_PCB && PCBCounter + numberOfPCB <= MAX_NUMBER_OF_PCB) { if (loopCounter % PRINT_EVERY_xTIMES == 0) { //fprintf(outFile, "\n__________NEXT TIME QUANTUM : %d___________\n", loopCounter); fprintf(outFile, "//----------------------------------\n"); fprintf(outFile, "We are creating %d PCBs \n\n", numberOfPCB); } for (i = 0; i < numberOfPCB; i++) { sprintf(processNameSetUp, "Process%d", PCBCounter); enqueue(PCBContainer, tempPCB = createPCB(processNameSetUp, PCBCounter, rand() % 15, 0, 1000 * PCBCounter, ready)); if (loopCounter % PRINT_EVERY_xTIMES == 0) { toStringFileVersion(tempPCB, outFile); } strcpy(processNameSetUp, "Process"); PCBCounter++; } } else if(PCBCounter == MAX_NUMBER_OF_PCB && loopCounter % 4 == 0) { fprintf(outFile, "We are done creating PCBs\n"); } if (loopCounter % PRINT_EVERY_xTIMES == 0) { fprintf(outFile, "//----------------------------------\n"); } //If we have started a running processes, increment the PC value to simulate running if (testingCPU->runningProcess != NULL) { testingCPU->runningProcess->pc += rand() % 1000 + 3000; //strcpy(testingCPU->systemStack->name, testingCPU->runningProcess->name); testingCPU->systemStack->pc = testingCPU->runningProcess->pc; } //else, create a temp "fake" processs PCB till a "real" one is created else { testingCPU->runningProcess = createPCB("Default", 0, 0, 0, 0, running); testingCPU->systemStack = createPCB("Default", 0, 0, 0, 0, running); } //Simulate Timer Interrupt timerISR(testingCPU, PCBContainer); if (loopCounter % PRINT_EVERY_xTIMES == 0) { //PRINT RESULTS AFTER TIMER ISR fprintf(outFile, "\nRunning process: \n"); //printf("//--------------------------------------\n"); toStringFileVersion(testingCPU->runningProcess, outFile); fprintf(outFile, "//---------------------------------------\n\n"); fprintf(outFile, "State of the Ready Queue: \n\n"); printListFileVersion(testingCPU->readQueue_p, outFile); fprintf(outFile, "\n\n"); } //pseudo halt for debug screen //getchar(); //one run has passed loopCounter++; } //free used memory freeLinkedList(PCBContainer); freeCPU(testingCPU); }