FCFS(First Come, First Served) FCFS will be applied to MLFQ's last queue A first came process will be finished at first >>> P1 = Process("P1", 0, 53) >>> P2 = Process("P2", 0, 17) >>> P3 = Process("P3", 0, 68) >>> P4 = Process("P4", 0, 24)
(self, ready_queue: deque[Process])
| 148 | return process.waiting_time |
| 149 | |
| 150 | def first_come_first_served(self, ready_queue: deque[Process]) -> deque[Process]: |
| 151 | """ |
| 152 | FCFS(First Come, First Served) |
| 153 | FCFS will be applied to MLFQ's last queue |
| 154 | A first came process will be finished at first |
| 155 | >>> P1 = Process("P1", 0, 53) |
| 156 | >>> P2 = Process("P2", 0, 17) |
| 157 | >>> P3 = Process("P3", 0, 68) |
| 158 | >>> P4 = Process("P4", 0, 24) |
| 159 | >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) |
| 160 | >>> _ = mlfq.first_come_first_served(mlfq.ready_queue) |
| 161 | >>> mlfq.calculate_sequence_of_finish_queue() |
| 162 | ['P1', 'P2', 'P3', 'P4'] |
| 163 | """ |
| 164 | finished: deque[Process] = deque() # sequence deque of finished process |
| 165 | while len(ready_queue) != 0: |
| 166 | cp = ready_queue.popleft() # current process |
| 167 | |
| 168 | # if process's arrival time is later than current time, update current time |
| 169 | if self.current_time < cp.arrival_time: |
| 170 | self.current_time += cp.arrival_time |
| 171 | |
| 172 | # update waiting time of current process |
| 173 | self.update_waiting_time(cp) |
| 174 | # update current time |
| 175 | self.current_time += cp.burst_time |
| 176 | # finish the process and set the process's burst-time 0 |
| 177 | cp.burst_time = 0 |
| 178 | # set the process's turnaround time because it is finished |
| 179 | cp.turnaround_time = self.current_time - cp.arrival_time |
| 180 | # set the completion time |
| 181 | cp.stop_time = self.current_time |
| 182 | # add the process to queue that has finished queue |
| 183 | finished.append(cp) |
| 184 | |
| 185 | self.finish_queue.extend(finished) # add finished process to finish queue |
| 186 | # FCFS will finish all remaining processes |
| 187 | return finished |
| 188 | |
| 189 | def round_robin( |
| 190 | self, ready_queue: deque[Process], time_slice: int |
no test coverage detected