CPU Scheduler algorithm Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. There are different non-preemptive algorithms to schedule CPU algorithms those are As follows :- 1.FCFS SCHEDULING ALGORITHM For FCFS scheduling algorithm, read the number of processes/jobs in the system , their CPU burst times. The scheduling is performed on the basis of arrival time of the processes irrespective of their other parameters. Each process will be executed according to its arrival time. Calculate the waiting time and turnaround time of each of the processes accordingly.
FCFS Scheduling algorithm Goal: To write a program for implementing FCFS scheduling algorithm. ALGORITHM: 1) F irstly, read the number of processes/jobs in the system, and their CPU burst time . 2) The scheduling performed on the basis of arrival time of the processes irrespective of their other parameters. 3) Each process will be executed according to its arrival time . 4 ) finally, Calculate the waiting time and turnaround time of each the processes accordingly .
Example1: FCFS process Burst Tim e P 24 P1 3 P2 3 Suppose that the processes arrive in the order: P ,P1,P2.
DESCRIPTION to the above running program N.B. Turnaround time – amount of time to execute a particular process Waiting time – amount of time a process has been waiting in the ready queue. let see the calculation how can we gained or the formula of the above result Waiting time:p0=0,p1=0+24=24,p2=0+24+3=27 Turnaround time=burst time +waiting time Total waiting time=total waiting time + waiting time Total Turnaround time= Total Turnaround time+Turnaroundtime Average waiting time= total waiting time/total n Average turnaround time= Total Turnaround time/total n where n is total number of process.
2 . SJF CPU SCHEDULING ALGORITHM For SJF scheduling algorithm, read the number of processes/jobs in the system , their CPU burst times. Arrange all the jobs in order with respect to their burst times. There may be two jobs in queue with the same execution time , and then FCFS approach is to be performed. Each process will be executed according to the length of its burst time. Then calculate the waiting time and turnaround time of each of the processes accordingly.
SJF Scheduling algorithm goal: To write a program for implementing SJF scheduling algorithm. ALGORITHM : 1) F irstly, read the number of processes/jobs in the system, and their CPU burst time . 2) Arrange all the jobs in order with respect to their burst times. 3) There may be two jobs in queue with the same execution time, and then FCFS approach is to be performed. 4) Each process will be executed according to the length of its burst time. 5)finally calculate the waiting time and turnaround time of each of the processes accordingly.
It is the same as FCFS in the a bove example 1 ,but the only difference is Arrange all the jobs in order with respect to their burst times. There may be two jobs in queue with the same execution time, and then FCFS approach is to be performed.
Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time . Waiting time:p1=0,p2=0+3=3,p0=0+3+3=6 Turnaround time=burst time +waiting time Total waiting time=total waiting time + waiting time Total Turnaround time= Total Turnaround time+Turnaroundtime Average waiting time=total waiting time/total n Average turnaround time= Total Turnaround time/total n where n is total number of process.
3 . PRIORITY CPU SCHEDULING ALGORITHM For priority scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times, and the priorities. Arrange all the jobs in order with respect to their priorities. There may be two jobs in queue with the same priority, and then FCFS approach is to be performed. Each process will be executed according to its priority . Calculate the waiting time and turnaround time of each of the processes accordingly.
Priority scheduling algorithm G oal : To write a program for implement the priority scheduling algorithm. ALGORITHM: read the number of processes/jobs in the system, their CPU burst times , and the priorities . Arrange all the jobs in order with respect to their priorities. There may be two jobs in queue with the same priority, and then FCFS approach is to be performed . Each process will be executed according to its priority. Calculate the waiting time and turnaround time of each of the processes accordingly.
In this one by adding priority Process is ordered based on priority. the smallest number of priority comes first ,then see to the burst time that are matched to the process. The other part is semis like the above algorithm.
The CPU is allocated to the process with the highest priority (smallest integer = highest priority). Waiting time:p2=0,p1=0+3=3,p0=0+3+3=6 Turnaround time=burst time +waiting time Total waiting time=total waiting time + waiting time Total Turnaround time= Total Turnaround time+Turnaroundtime Average waiting time=total waiting time/total n Average turnaround time= Total Turnaround time/total n where n is total number of process.
4.ROUND ROBIN CPU SCHEDULING ALGORITHM For round robin scheduling algorithm, read the number of processes/jobs in the system, their CPU burst times, and the size of the time slice. Time slices are assigned to each process in equal portions and in circular order, handling all processes execution . This allows every process to get an equal chance. Calculate the waiting time and turnaround time of each of the processes accordingly.
R ound R obin Scheduling algorithm Goal: to write a program for to implementing the round robin scheduling algorithm ALGORITHM: Firstly, read the number of processes/jobs in the system, their CPU burst times, and the size of the time slice. Time slices are assigned to each process in equal portions and in circular order, handling all processes execution. This allows every process to get an equal chance. Calculate the waiting time and turnaround time of each of the processes accordingly.
The only difference with the above algorithms that we are taking example is in this one we are going to use size of the time slice. This time slices is used to assigned to each process in equal portions and in circular order, handling all processes execution. This allows every process to get an equal chance. Let we use from the above example1.the time slice for instance tq =2.
5. Multi-Level Q ueue S cheduling A lgorithm Multi-level queue scheduling algorithm is used in scenarios where the processes can be classified into groups based on property like process type, CPU time, IO access, memory size, etc. In a multilevel queue scheduling algorithm, there will be 'n' number of queues, where 'n' is the number of groups the processes are classified into. Each queue will be assigned a priority and will have its own scheduling algorithm like FCFS . For the process in a queue to execute, all the queues of priority higher than it should be empty, meaning the process in those high priority queues should have completed its execution. In this scheduling algorithm, once assigned to a queue, the process will not move to any other queues.
Multi-Level Q ueue S cheduling A lgorithm Goal: : to write a program for to implement multi-level queue scheduling algorithm ALGORITHM: Firstly, there will be 'n' number of queues, where 'n' is the number of groups the processes are classified into. Each queue will be assigned a priority and will have its own scheduling algorithm like FCFS scheduling algorithm. For the process in a queue to execute, all the queues of priority higher than it should be empty , meaning the process in those high priority queues should have completed its execution. Lastly In this scheduling algorithm, once assigned to a queue, the process will not move to any other queues.
In this algorithm we use 0 for system process 1 for user process. Let use from example 1.