int main(void) { srand ( time(NULL) ); //create a new PCB with priority between 0 - 15 and test getters printf ("Create PCB:\n"); PCB_p PCBTest1 = create("PCB1", 1, rand()%15); printf ("Name: %s and Process ID: %d and Priority: %d\n", getName(PCBTest1), getPid(PCBTest1), getPriority(PCBTest1)); // test toString() method printf("Test toString()\n"); toString(PCBTest1); printf("\n"); //free PCB printf ("Free PCB:\n"); freePCB(PCBTest1); toString(PCBTest1); printf("\n"); //test create PCB with wrong type for NAME --- EXECUTION FAILS // PCB_p PCBTest2 = create(5, 1, 4); // toString(PCBTest2); printf("\n"); //test create PCB with wrong type PID --- Creates PCB and RETURNS RANDOM VALUE PCB_p PCBTest3 = create("PCB3", "1", rand()%15); toString(PCBTest3); printf("\n"); //test create PCB with non-int priority PCB_p PCBTest4 = create("PCB4", 1, "c"); toString(PCBTest4); printf("\n"); //test create PCB with priority value > 15 PCB_p PCBTest5 = create("PCB5", 1, 16); toString(PCBTest5); printf("\n"); //test create PCB with priority value < 0 PCB_p PCBTest6 = create("PCB6", 1, -1); toString(PCBTest6); printf("\n"); return 0; }
//Deletes the PCB from the MPX system void deletePCB(char PCBName[20]){ PCB *pcbPointer; pcbPointer = findPCB(PCBName); removePCB(pcbPointer); freePCB(pcbPointer); }
void interrupt sys_call(void){ static IOD *temp; //Saves the ss and sp register to a temp storage ss_save2 = _SS; sp_save2 = _SP; COP->stack = (unsigned char *)MK_FP(ss_save2,sp_save2); //Updates the stacktop for context switch //Access Parameters that sys_req placed on the stack param_ptr = (params*)(COP->stack+sizeof(context)); //Switching to a temp stack new_ss = FP_SEG(sys_stack); new_sp = FP_OFF(sys_stack)+ SYS_STACK_SIZE; _SS = new_ss; _SP = new_sp; trm_getc(); if(TerminalQueue->event_flag==1 && TerminalQueue->count > 0){ TerminalQueue->event_flag = 0; temp = TerminalQueue->head; TerminalQueue->head = TerminalQueue->head->next; unblockPCB(temp->ppt->processName); sys_free_mem(temp); TerminalQueue->count--; if(TerminalQueue->count!=0){ ProcessIORequest(1); } } if(Com_PortQueue->event_flag==1 && Com_PortQueue->count > 0){ Com_PortQueue->event_flag = 0; temp = Com_PortQueue->head; Com_PortQueue->head = Com_PortQueue->head->next; unblockPCB(temp->ppt->processName); sys_free_mem(temp); Com_PortQueue->count--; if(Com_PortQueue->count!=0){ ProcessIORequest(1); } } //Process is idle if (param_ptr -> op_code == IDLE){ //Sets state to running and adds it back into the readyQueue COP -> state = 2; PriorityEnqueue(readyQueue,COP); } //Process is completed and ready for deletion if (param_ptr -> op_code == EXIT){ //Frees the memory of the PCB and sets the PCB to NULL freePCB(COP); COP = NULL; } if (param_ptr -> op_code == READ ||param_ptr -> op_code == WRITE ||param_ptr -> op_code == CLEAR ||param_ptr -> op_code == GOTOXY ){ IOScheduler(); } //Dispatches the next process in the readyQueue dispatch(); }