Annotated Bibliography On Functions And Functions

1570 WordsJun 21, 20167 Pages
#include #include #include #include #include #include int PID[100], CPU_time[100], IO_time[100], arrival_time[100], flags[100],ID_ready[100]; int rQ[100], bQ[100]; int f_CPU = 0, r_CPU = 0, f_IO = 0, r_IO = 0; // a function that dequeue an element from a queue int deque(int state, int N, int ID) { int temp, var, i, index; if (state == 0) { //deque from ready_queue var = rQ[f_CPU]; rQ[f_CPU] = -1; f_CPU++; if (f_CPU == N) f_CPU = 0; } if (state == 1) { //deque from blocked_queue for (i = 0; i < N; i++) { //search for ID in the blocked queue if (bQ[i] == ID) { index = i; break; } } if (bQ[f_IO] != ID) { //sort the elements of the blocked_queue to deque from the place pointed by f_IO temp = bQ[f_IO]; bQ[f_IO] = ID; bQ[index] = temp; } var = bQ[f_IO]; bQ[f_IO] = -1; f_IO++; if (f_IO == N) //check if end of queue reached f_IO = 0; flags[ID] = 0; } return var; } // a function that enqueue an element in a queue void enque(int _id, int state, int N) { if (state == 0) { //enque in ready_queue rQ[r_CPU] = _id; r_CPU++; if (r_CPU == N) r_CPU = 0; } else { //enque in blocked_queue bQ[r_IO] = _id; r_IO++; if (r_IO == N) r_IO = 0; flags[_id] = 1; } } // a function for first come first served algorithm void FCFS(int N) { int n, m, k, p, j, ID, time = 0, temp, counter = -1, run_flag = 0, finish_counter = 0; int turnaround_time[N], data[N]; float run_count = 0; FILE *output = fopen("FCFS.out",
Open Document