Make CPU scheduler program (C Code)
Implementation CPU Scheduling
FCFS, RR (Round-Robin), SPN, SRT, MLFQ, Lottery Scheduling (with C code)
The FCFS scheduling policy is non-preemptive so cannot be affected by another process until one running process finishes. Therefore, by checking the process arrival time every second, the arriving processes are put in the ready queue in the order of arrival, and then the ready queue is checked only when there is no running process according to the non-preemptive method, and the process that arrived first is moved to the running queue and executed.
After that, if the running process is terminated, the running queue is emptied, and if there are elements left in the ready queue, it is programmed to be scheduled in the order of arrival first.
The RR scheduling policy is a preemptive type, and it is designed so that the user can arbitrarily assign time quantum by receiving the time quantum factor to be used at this time.
First of all, in the scheduling method, if there is no running process, run the process that came first from the ready queue, check the time quantum given to each process every second, and if the service ends before the time quantum, run the next process, and if there is still service time I made it go to the back of the ready queue.
The SPN scheduling policy is a non-preemptive policy that prioritizes the process with the shortest execution time.
According to the non-preemptive method, only when there is no running process, the processes in the ready queue are sorted as those with the shortest running time, so that the process with the shortest running time is executed first, and if there was an original running process, it is programmed to go to the back of the ready queue.
The SRT scheduling policy introduces a preemptive method from the SPN scheduling technique.
Therefore, I compared all the processes in the ready queue and the running queue every second and moved the process with the shortest remaining service time to the running queue and executed it.
This is a technique that was developed to prevent the process from waiting for a long service time. It is a non-preemptive method in which the process with the highest response rate is scheduled first.
Therefore, according to the non-preemptive method, only when there is no execution process, the elements in the ready queue are sorted in the order of the highest response rate, and then the first element is run.
<Response rate: (service time + waiting time)/ service time>
When implementing the MLFQ, the total number of queues was 3 (level 0, level 1, level 2). At this time, the time given to each level is set to increase to mlfq_time^0, mlfq_time^1, and mlfq_time^2 using the mlfq_time received as the third argument.
In addition, the level of the queue scheduled in each level was memorized, and if all the allotted time was used, each level was lowered.
Tickets for each process were set in proportion to the service time of the process, the number of ready queue elements was identified every second, a random number was created after adding the number of tickets for the elements, and scheduling was performed according to the number.
Process_name | Arrival_time (sec) | Service_Time (sec) |
---|---|---|
A | 0 | 3 |
B | 2 | 6 |
C | 4 | 4 |
D | 6 | 5 |
E | 8 | 2 |
Process_name | Arrival_time (sec) | Service_Time (sec) |
---|---|---|
A | 0 | 4 |
B | 1 | 3 |
C | 4 | 6 |
D | 7 | 2 |
E | 9 | 3 |