/*Randomly generates between 0 and 5 new processes and enqueues them to the New Processes Queue.*/ void genProcesses() { PcbPtr newProc; int i; // rand() % NEW_PROCS will range from 0 to NEW_PROCS - 1, so we must use rand() % (NEW_PROCS + 1) for(i = 0; i < rand() % (NEW_PROCS + 1); i++) { newProc = PCBConstructor(); if(newProc != NULL) // Remember to call the destructor when finished using newProc { currPID++; PCBSetID(newProc, currPID); PCBSetPriority(newProc, rand() % PRIORITY_LEVELS); PCBSetState(newProc, created); fifoQueueEnqueue(newProcesses, newProc); printf("Process created: PID: %d at %lu\r\n", PCBGetID(newProc), PCBGetCreation(newProc)); //printf("Process created: %s\r\n", PCBToString(newProc)); } } }
int main(void) { srand(time(NULL)); currPID = 0; sysStackPC = 0; /*io1Count = -1; io2Count = -1;*/ timerCount = TIMER_QUANTUM; newProcesses = fifoQueueConstructor(); readyProcesses = fifoQueueConstructor(); terminatedProcesses = fifoQueueConstructor(); device1 = IODeviceConstructor(); device2 = IODeviceConstructor(); printf("Sean Markus\r\nWing-Sea Poon\r\nAbigail Smith\r\nTabi Stein\r\n\r\n"); //An initial process to start with currProcess = PCBConstructor(); if(currProcess != NULL) // Remember to call the destructor when finished using newProc { PCBSetID(currProcess, currPID); PCBSetPriority(currProcess, rand() % PRIORITY_LEVELS); PCBSetState(currProcess, running); //fifoQueueEnqueue(newProcesses, currProcess); printf("Process created: PID: %d at %lu\r\n", PCBGetID(currProcess), PCBGetCreation(currProcess)); // printf("Process created: %s\r\n", PCBToString(currProcess)); cpu(); } //free all the things! fifoQueueDestructor(&newProcesses); fifoQueueDestructor(&readyProcesses); fifoQueueDestructor(&terminatedProcesses); IODeviceDestructor(device1); IODeviceDestructor(device2); printf("End of simulation\r\n"); return 0; }
int main(int argc, char *argv[]) { //printf("working"); if (argc == 9) { process_count = atoi(argv[2]); kproc_count = atoi(argv[4]); ioproc_count = atoi(argv[6]); pcproc_count = atoi(argv[8]); calcproc_count = process_count - (kproc_count + ioproc_count + (pcproc_count * 2)); } else { process_count = 15; kproc_count = 3; ioproc_count = 3; pcproc_count = 3; calcproc_count = 3; } ReadyQPtr = QueueConstructor(); int i; for (i = 0; i < kproc_count; i++) { PCBPtr a = PCBConstructor(processidcount, 2, 2, -1); enqueue(ReadyQPtr, a); processidcount++; } for (i = 0; i < pcproc_count; i++) { PCBPtr c = PCBConstructor(processidcount, 3, 2, i); enqueue(ReadyQPtr, c); processidcount++; PCBPtr d = PCBConstructor(processidcount, 4, 2, i); enqueue(ReadyQPtr, d); processidcount++; } for (i = 0; i < calcproc_count; i++) { PCBPtr e = PCBConstructor(processidcount, 0, 2, -1); enqueue(ReadyQPtr, e); processidcount++; } for (i = 0; i < ioproc_count; i++) { PCBPtr b = PCBConstructor(processidcount, 1, 2, -1); enqueue(ReadyQPtr, b); processidcount++; } for (i = 0; i < pcproc_count; i++) { sharedMemory[i] = 0; } //initialize interrupt flags IO1INT = 0; IO2INT = 0; KBINT = 0; TIMERINT = 0; KBHASPCB = 0; //printf("\nProcess Count %d", process_count); //printQueue(ReadyQPtr); //printf("\nProcess Count2"); cpuPtr cpu = cpuConstructor(); //printf("\nCPU Program Complete"); CPURun(cpu); return 0; }