Several process scheduling algorithms in the operating system

First come first served scheduling algorithm

The first-come-first-served (FCFS) scheduling algorithm is one of the simplest scheduling algorithms, which can be used for both job scheduling and process scheduling. The FCFS algorithm is more conducive to long jobs (processes) than to short jobs (processes). Therefore, this algorithm is suitable for CPU busy jobs, but not conducive to I / O busy jobs (processes).

What are CPU busy jobs and what are I / O busy jobs?
The former requires a lot of full and even overloaded integer and floating-point operations, mainly operating in memory, as the saying goes, it eats U, such as various scientific calculations, large-scale data modeling, etc., the latter is required Frequently read and write hard disks or other storage media, such as various data centers, network storage and cloud storage servers

Advantages and disadvantages:

  • More conducive to long jobs (processes), but not conducive to short jobs (processes)
  • Beneficial for CPU busy jobs (processes) but not for I / O busy jobs (processes)
  • Used in batch processing system, not suitable for time-sharing system

Short job priority scheduling algorithm

Short job (process) priority scheduling algorithm (SJ / PF) refers to an algorithm that prioritizes short jobs or short processes. This algorithm can be used for both job scheduling and process scheduling. But it is not good for long jobs; there is no guarantee that urgent jobs (processes) are processed in a timely manner; the length of the job is only estimated.

Advantages and disadvantages:

  • Unfavorable for long-term work, make long-term work into a hungry state.
  • The urgency of the job (process) is not considered at all, so there is no guarantee that the urgent job (process) will be processed in time.
  • Because the length of the job (process) is only based on the estimated execution time provided by the user, and the user may intentionally or unintentionally shorten the estimated running time of his job, so that the algorithm may not be able to truly schedule short jobs

Priority scheduling algorithm

In order to take care of urgent tasks and get priority treatment after entering the system, the highest priority first (FPF) scheduling algorithm is introduced. This algorithm is often used in batch processing systems, as a job scheduling algorithm, and as a process scheduling algorithm in a variety of operating systems. It can also be used in real-time systems. When this algorithm is used for job scheduling, the system will select several jobs with the highest priority from the back-up queue and load them into memory. When used for process scheduling, the algorithm is to assign the processor to the process with the highest priority in the ready queue. At this time, the algorithm can be further divided into the following two types.

Non-preemptive priority algorithm

In this way, once the system assigns the processor to the process with the highest priority in the ready queue, the process will continue to execute until completion; or when an event occurs that causes the process to abandon the processor, the system can then Reassign the processor to another process with the highest priority. This scheduling algorithm is mainly used in batch processing systems; it can also be used in some real-time systems that have strict requirements on real-time performance.

Preemptive priority scheduling algorithm

In this way, the system also assigns the processor to the process with the highest priority for execution. But during its execution, as long as another process with higher priority appears, the process scheduler will immediately stop the execution of the current process (the process with the highest priority) and reassign the processor to the newly arrived priority The highest process. Therefore, when this scheduling algorithm is adopted, whenever a new ready process i appears in the system, its priority Pi is compared with the priority Pj of the process j being executed. If Pi≤Pj, the original process Pj will continue to execute; but if Pi> Pj, then immediately stop the execution of Pj, do process switching, so that the i process is put into execution. Obviously, this preemptive priority scheduling algorithm can better meet the requirements of urgent operations, so it is often used in real-time systems with strict requirements, and batch processing and time-sharing systems with high performance requirements.

High responsive priority scheduling algorithm

In batch processing systems, the short job priority algorithm is a better algorithm, and its main disadvantage is that the operation of long jobs cannot be guaranteed. If we can introduce the dynamic priority mentioned above for each job, and make the priority of the job increase at a rate with the increase of waiting time, then after waiting for a certain time for a long job, there must be a chance to be allocated to processing machine. The change rule of the priority can be described as follows
Insert picture description here
:

(1) If the waiting time of the job is the same, the shorter the time required for service, the higher its priority, so the algorithm is conducive to short jobs.
(2) When the required service time is the same, the priority of the job is determined by its waiting time. The longer the waiting time, the higher the priority, so it implements first-come-first-served.
(3) For long jobs, the priority of the job can be increased with the increase of the waiting time. When the waiting time is long enough, the priority can be raised to a high level, so that the processor can also be obtained. In short, the algorithm takes care of both short jobs and the order of arrival of the jobs, and does not leave long jobs unserviced for a long time. Therefore, the algorithm achieves a better compromise. Of course, when using this algorithm, the response ratio must be calculated before scheduling, which will increase the system overhead.

Round-robin scheduling algorithm

Give each process a fixed execution time, let the process execute in a unit time slice according to the order in which the process arrives, and schedule the next process execution after the execution is completed. Time slice rotation scheduling does not consider the process waiting time and execution time, which is preemptive Scheduling. The advantage is to balance both long and short jobs; the disadvantage is that the average waiting time is longer, and the context switch is more time-consuming. Suitable for time-sharing systems.

Multi-level feedback queue

The various algorithms used for process scheduling described above have certain limitations. For example, the short process priority scheduling algorithm only takes care of the short process and ignores the long process, and if the length of the process is not specified, the short process priority and the preemptive scheduling algorithm based on the process length will not be used. The multi-level feedback queue scheduling algorithm does not need to know the execution time required by various processes in advance, and can also meet the needs of various types of processes, so it is currently recognized as a better process scheduling algorithm. In a system employing a multi-level feedback queue scheduling algorithm, the implementation process of the scheduling algorithm is as follows.

(1) Multiple ready queues should be set up, and each queue should be given different priority. The first queue has the highest priority, the second queue comes next, and the priority of the remaining queues decreases one by one. The algorithm assigns different sizes of process execution time slices in each queue. The higher the priority, the smaller the execution time slice specified for each process. For example, the time slice of the second queue is twice as long as the time slice of the first queue ..., the time slice of the i + 1th queue is twice as long as the time slice of the ith queue.

(2) When a new process enters memory, it is first put into the end of the first queue, and queued up for scheduling according to the FCFS principle. When it is the turn of the process to execute, if it can complete within the time slice, it can prepare to evacuate the system; if it is not completed at the end of a time slice, the scheduler will transfer the process to the end of the second queue, and then Similarly, wait for the scheduled execution according to the FCFS principle; if it is not completed after running a time slice in the second queue, then put it into the third queue in turn ..., so, when a long job (process) starts from the first After a queue descends to the nth queue in turn, the nth queue runs in a time slice rotation manner.

(3) Only when the first queue is idle, the scheduler schedules the processes in the second queue; only when the first to (i-1) queues are empty, the process in the i-th queue is scheduled to run. If the processor is serving a process in the i-th queue, and a new process enters the queue with a higher priority (any queue in the first to (i-1)), then the new process will preempt the running The processor of the process, that is, the scheduler puts the running process back to the end of the i-th queue, and assigns the processor to the newly arrived high-priority process.
Advantages:
  Take care of short processes to improve system throughput and shorten average turnaround time.
  Take care of I / O-type processes in order to obtain better I / O device utilization and shorten response time.
  No need to estimate the execution time of the process, dynamic adjustment

Published 181 original articles · Like 13 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/qq_43461641/article/details/105072930