int main(void){ CPU_p new_cpu = CPU_constructor(); new_cpu->pid = 11; new_cpu->pc = 11100; new_cpu->sw = 2442828; new_cpu->address = 12322; new_cpu->p_state = READY; printf("CPU: PID:%u PC:%u SW:%u ADDRESS:%u\n", new_cpu->pid, new_cpu->pc, new_cpu->sw, new_cpu->address); CPU_destructor(new_cpu); return 0; }
int main() { // Prepare for file writing: CPU_remove_file(); // House Keeping: file = fopen("scheduleTrace.txt", "w+"); srand(time(0)); // Seed random generator unsigned int PC = 0; int total_procs = 0, process_ID = 1; // Create CPU: CPU *cpu = CPU_constructor(); // CPU: Represent a time quantum. Assumed every process has the same time quantum. int time_count = 1; //total_procs <= MAX_PROCESS - 5 while (total_procs < MAX_PROCESS) { fprintf(file, "***************TIME QUANTUM = %d***************\n", time_count); // 1a. Create a queue of new processes, 0 - 5 processes at a time: int num_proc_created = 0; do { num_proc_created = rand() % 6; } while (total_procs + num_proc_created > MAX_PROCESS); fprintf(file, "Process randomed: %d\n", num_proc_created); total_procs += num_proc_created; cpu->newProcessesQueue = CPU_create_processes(cpu->newProcessesQueue, num_proc_created, process_ID); process_ID += num_proc_created; // 1c. Print newly created processes queue to file: fprintf(file, "New processes initialized: %d. Total processes: %d\n", num_proc_created, total_procs); fprintf(file, "Newly created processes list: %s", Queue_toString(cpu->newProcessesQueue, 0)); // puts head of readyQueue as current process and changes state to running // if (cpu->currentProcess == empty_pcb && !Queue_isEmpty(cpu->readyQueue)) { // cpu->currentProcess = Queue_dequeue(cpu->readyQueue); // PCB_set_state(cpu->currentProcess, running); // } unsigned int random = rand() % 1001 + 3000; if (random < 3000) { random = rand() % 1001 + 3000; } PC += random; fprintf(file, "Current PC: %d. System Stack: %d\n", PC, cpu->sysStack); //if (cpu->currentProcess != NULL) CPU_push_sysStack(cpu, PC); // calls pseudo ISR CPU_pseudo_isr(cpu, PC); fprintf(file, "Current PC: %d. System Stack: %d\n\n", PC, cpu->sysStack); CTX_SWITCH_COUNT++; time_count++; } fclose(file); CPU_destructor(cpu); return 0; }