Analysis of several common process scheduling algorithms

Source: Internet
Author: User

today to talk about the operating system of several common process scheduling algorithm. So the first step is to understand what a process scheduling algorithm is? In simple terms, the resource allocation algorithm is based on the resource allocation strategy of the system. Give an example to illustrate. Assuming that a task is selected after execution completes to minimize a factor, this factor may be the total time of the process execution or the disk seek time, and so on. Therefore, there are different requirements for different system targets, and the scheduling algorithm to be chosen is not the same. Next, we'll talk about a few common process scheduling algorithms.

first>> first come first service scheduling algorithm FCFS

  first come first service (FCFS) scheduling algorithm is the simplest scheduling algorithm, which can be used for both job scheduling and process scheduling. When this algorithm is used in job scheduling, each schedule selects one or more jobs that first enter the queue from the fallback job queue, puts them into memory, assigns them resources, creates processes, and then puts them in the ready queue. When the FCFS algorithm is used in the process scheduling, each schedule is to select a process from the ready queue that is first entered into the queue, assigning the processor to it and putting it into operation. The process has been running until it has completed or an event has been blocked before discarding the processor.

There are some drawbacks in this method of taking the FIFO of the queue. It is better for long work than for short work. It is advantageous to the CPU busy job, but is not conducive to the I/O busy job.

second>> Short Job (process) Priority scheduling algorithm SJ (P) F

Short job (process) Priority scheduling algorithm SJ (P) F, refers to the algorithm for short or short process priority scheduling. They can be used for job scheduling and process scheduling, respectively. The scheduling algorithm for short job first (SJF) is to select one or several jobs with the shortest estimated run time from the fallback queue and transfer them into the memory run. The short process first (SPF) scheduling algorithm chooses a process that estimates the shortest running time from the ready queue, assigns the processor to it, causes it to execute immediately and executes until it is completed, or when an event is blocked to abort the processor and then re-dispatched.

third>> high priority priority scheduling algorithm FPF

priority scheduling algorithm

We know that some jobs need to be executed immediately, so in order to meet this priority, the operating system introduces the highest priority priority algorithm (FPF). This algorithm is often used in batch processing system, as a job scheduling algorithm, also as a variety of operating system process scheduling, can also be used in real-time systems. When it is used for job scheduling, a number of the highest priority jobs in the fallback queue are loaded into memory. When it is used for process scheduling, the processor is assigned to the highest priority process in the ready queue. So we can divide it into two types to illustrate.

(1) Non-preemptive priority algorithm

In this way, once the system has allocated the processor to the highest priority process in the ready queue, the process continues until it is completed, or the system can reassign the processor to another process that has the highest priority because of an event that causes the process to abandon the processor. This scheduling algorithm is mainly used in batch processing systems, and can also be applied to some real-time systems where real-time requirements are not stringent.

(2) Preemptive priority scheduling algorithm

In this way, the system also assigns the processor to the process with the highest priority and makes it execute. During its execution, however, as soon as another process with its higher priority arises, the process scheduler immediately stops the execution of the current process (the one that has the highest priority) and re-assigns the processor to the new highest priority process. Therefore, when this scheduling algorithm is used, the priority pi is compared with the priority PJ of the executing process J whenever a new ready process I is present in the system. If PI≤PJ, the original process PJ will continue to execute, but if it is PI>PJ, then immediately stop the execution of PJ, do a process switch, so that I process into execution. Obviously, this preemptive priority scheduling algorithm can better meet the requirements of urgent operation, so it is often used in the demanding real-time system, and in the batch processing and timeshare system with high performance requirements.

High response ratio priority scheduling algorithm:

In batch processing system, the short job first algorithm is a better algorithm, and its main disadvantage is that the operation of long operation is not guaranteed. If we can introduce the dynamic priority described above for each job, and the priority of the job increases with the wait time to increase at rate A, then the long job waits for a certain period of time, there must be a chance to assign to the processor. The change law of this priority can be described as:

priority = (wait time + request service time)/Request service time


As the sum of waiting time and service time is the response time of the system to the job, the priority is equal to the response than the RP. Accordingly, it can also be expressed as:

Priority = Response Time/Request Service time

      (1) If the waiting time of the job is the same, the shorter the service time and the higher the priority, so the algorithm is advantageous to the short job.
      (2) when the time required for service is the same, the priority of the job depends on its waiting time, the longer the waiting time, the higher its priority, Thus it realizes that first comes first service.
      (3) for long jobs, the priority of the job can increase with the wait time, and when its wait time is long enough, The priority can be raised to a high level, which can also be obtained from the processor.

forth>> algorithm based on time slice for rotation scheduling

Time Slice rotation method:

  in the early time-slice rotation method, The system queues all the ready processes on a first-come-first-served basis, allocating the CPU to the team's first process and making it perform a time slice each time it is scheduled. The size of the time slice is from several ms to hundreds of Ms. When the elapsed time slice runs out, the clock interrupt request is made by a timer, which signals the scheduler to stop the execution of the process and sends it to the end of the ready queue, and then assigns the processor to the new team first process in the ready queue, while also allowing it to execute a time slice. This ensures that all processes in the ready queue can receive a time slice of processor execution times within a given time. In other words, the system can respond to requests from all users within a given time.

Multilevel Feedback queue scheduling algorithm:  

The various algorithms used in the process scheduling have some limitations. such as the short process first scheduling algorithm, only take care of the short process and ignore the long process, and if the length of the process is not indicated, the short process first and process-based preemptive scheduling algorithm will not be used. The multi-level feedback queue scheduling algorithm does not need to know the execution time of various processes in advance, but also can satisfy the needs of various types of processes, so it is now recognized as a good process scheduling algorithm. In the system using multilevel feedback queue scheduling algorithm, the implementation process of scheduling algorithm is described below.
(1) You should set up multiple ready queues and assign different priorities to each queue. The first queue has the highest priority, the second queue is followed, and the priority of the remaining queues is lowered one by one. The algorithm gives each queue the size of the process execution time slices, and in the higher priority queue, the execution time slices for each process are smaller. For example, the time slice of the second queue is one times longer than the time slice of the first queue ..., the time slice of the i+1 queue is one times longer than the time slice of the I queue.
(2) When a new process enters memory, it is first placed at the end of the first queue and queued for dispatch by the FCFS principle. When it is time for the process to execute, it can prepare the evacuation system if it can be completed on the chip, and if it is not completed at the end of a time slice, the scheduler moves the process to the end of the second queue, and then similarly waits for dispatch execution by the FCFS principle, if it is still not completed after running a time slice in the second queue Then put it in the third queue, ..., and so on, when a long job (process) from the first queue down to the nth queue, in the nth queue will be taken by the time slice rotation operation.
(3) The scheduler dispatches the processes in the second queue only when the first queue is idle, and the processes in queue I are scheduled to run only if the 1~ (i-1) queue is empty. If the processor is servicing a process in queue I, and a new process enters a higher priority queue (1~ (i-1)), then the new process will preempt the processor that is running the process, that is, the scheduler puts the running process back to the end of the queue. Assign the processor to the new high priority process.

This article is from the "July boreas" blog, please be sure to keep this source http://luminous.blog.51cto.com/10797288/1786373

Analysis of several common process scheduling algorithms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.