Common scheduling algorithms for operating systems

Source: Internet
Author: User

There are many scheduling algorithms in the operating system, some of which are suitable for job scheduling, some scheduling algorithms are suitable for process scheduling, and some scheduling algorithms are applicable. Here are a few common scheduling algorithms.

1. first come first service (FCFS) scheduling algorithm

FCFS scheduling algorithm is one of the simplest scheduling algorithms, the scheduling algorithm can be used for job scheduling can also be used for process scheduling. In job scheduling, each time the algorithm selects one or more jobs from the fallback job queue that first enters the queue, it puts them into memory, allocates the necessary resources, creates the processes, and puts them in the ready queue.

in process scheduling, FCFS each time the scheduling algorithm chooses the process that first enters the queue from the ready queue, it assigns the processor to it and puts it into operation until it is complete or blocked for some reason to release the processor.

FCFS The scheduling algorithm belongs to the non-deprivation algorithm. On the surface, it is fair to all jobs, but if a long job arrives at the system first, it will cause many short jobs to wait for a long time, so it can not be used as the main scheduling strategy of time-sharing system and realtime system. However, it is often used in conjunction with other scheduling strategies. For example, in a system that uses precedence as a scheduling policy, multiple processes with the same priority are often treated as FCFS principles.

FCFS SJF and high response ratio); cpu i/o busy type of job.

2. Span style= "font:9px" Times New Roman '; " >      short job first ( SJF "scheduling algorithm

short Job (process) Priority scheduling algorithm refers to the algorithm of the short job (process) priority scheduling. They can be used for job scheduling and process scheduling, respectively. the short job first (SJF) scheduling algorithm 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 to execute immediately, and then releases the processor until it is blocked by the completion or occurrence of an event.

SJF disadvantages of the scheduling algorithm:

① The algorithm is unfavorable to the long operation, The turnaround time of the long job in SJF scheduling algorithm is increased. More seriously, if there is a long job going into the system's back-up queue, because the scheduler always prioritizes those ( Even the last-coming) short jobs, it will cause long jobs to be scheduled for long periods of time.

② The algorithm does not take into account the urgency of the operation, so the urgency of operation will not be guaranteed to be processed in time.

③ because the length of the job 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 their work, the algorithm does not necessarily really do short-job priority scheduling.

3. Priority scheduling Algorithm

Priority scheduling algorithm is also called priority scheduling algorithm, which can be used for job scheduling and process scheduling, and the priority of the algorithm is used to describe the urgency of job operation. In job scheduling, the priority scheduling algorithm selects one or more of the highest priority jobs from the fallback job queue each time, puts them into memory, allocates the necessary resources, creates processes, and puts them in the ready queue. In the process scheduling, the priority scheduling algorithm selects the highest priority process from the ready queue, assigns the processor to it and puts it into operation.

depending on whether the new higher-priority process can preempt the process being executed, the scheduling algorithm can be divided into: ① non-deprivation priority scheduling algorithm. When a process is running on a processing machine, even if there is a more important or urgent process going into the ready queue, the running process continues to run until the processor is voluntarily given up for its own reasons (task completion or wait events), assigning the processor to a more important or urgent process.

② deprivation-based priority scheduling algorithm. When a process is running on a processing machine, if a more important or urgent process enters the ready queue, the running process is immediately suspended and the processor is assigned to a more important or urgent process.

Depending on whether the priority can be changed after the process is created, you can divide the process priority into the following two types:

① static precedence. The priority is determined when the process is created and remains the same throughout the duration of the process. The main basis for determining the static priority is the process type, the resource requirements of the process, and the user requirements.

② dynamic priority. The priority is dynamically adjusted as the process changes as the process runs. The main basis for dynamically adjusting the priority is the length of CPU time that the process occupies, and how long the ready process waits for CPU time.

4. High response ratio priority scheduling algorithm

the high response ratio priority scheduling algorithm is mainly used for job scheduling, and the algorithm is FCFS Scheduling Algorithms and SJF A comprehensive balance of the scheduling algorithm, taking into account the waiting time and estimated run time of each job. In each job schedule, the response ratio of each job in the fallback job queue is calculated first, and the highest response is selected to run.

650) this.width=650; "title=" Qq20160616222135.png "src=" http://s3.51cto.com/wyfs02/M01/82/DC/ Wkiom1divm6duwhnaaartgvbhp0250.png "alt=" Wkiom1divm6duwhnaaartgvbhp0250.png "/>

According to the formula:

① when the waiting time of the job is the same, the shorter the service time is required, the higher the response ratio is, which is advantageous to the short job.

② When the service time is required, the response of the job is more than the waiting time, the longer the wait time, the higher the response ratio, so it realizes the first-come-first service.

③ for long jobs, the response of the job can increase with the waiting time, when its waiting time is long enough, its response ratio can rise to very high, thus also can obtain the processor. Overcome the hunger, taking into account the long work.

5. time-Slice rotation scheduling algorithm

time-Slice rotation scheduling algorithm is mainly applicable to the timeshare system. In this algorithm, the system queues up all the ready processes in the order of arrival time, and the process scheduler always chooses the first process in the ready queue, i.e. the principle of first-come-first service, but only one time slice, such as 100ms, can be run . After a time slice is used, even if the process does not complete its operation, it must also release the (stripped) processor to the next ready process, and the stripped process returns to the end of the ready queue to be queued again, waiting to run again.

In the time-slice rotation scheduling algorithm, the size of the time slice has a great influence on the performance of the system. If the time slice is large enough that all processes can be executed in a single time slice, then the time-slice rotation scheduling algorithm degrades to the first-come-first service scheduling algorithm. If the time slice is small, then the processor will switch too frequently between processes, making the processor more expensive, and the actual time spent running the user process will be reduced. Therefore the size of the time slice should be chosen appropriately.

The length of time slices is usually determined by the response time of the system, the number of processes in the ready queue, and the processing power of the system.

6. Multilevel Feedback Queue scheduling algorithm (the advantages of the previous algorithms are set)

The multilevel feedback queue scheduling algorithm is the synthesis and development of the time slice rotation scheduling algorithm and the priority scheduling algorithm, and the multilevel feedback queue scheduling algorithm can take into account many system targets by dynamically adjusting the process priority and the time slice size. For example, take care of short processes to improve system throughput and shorten average turnaround time , take care of I/O processes for better I/O Device utilization and reduce response time , and You do not have to estimate the execution time of the process beforehand.

Multilevel feedback queue scheduling algorithm:

650) this.width=650; "title=" Qq20160616223220.png "src=" http://s5.51cto.com/wyfs02/M01/82/DC/ Wkiom1divojdsgwjaacqvvm93vc010.png "alt=" Wkiom1divojdsgwjaacqvvm93vc010.png "/>

The realization of multilevel feedback queue scheduling algorithm is as follows:

(1) You should set up multiple ready queues and give different priorities to each queue, the 1th-level queue has the highest priority, the 2nd-level queue is the second, and the remaining queues have a lower priority.

(2) The size of the process execution time slices in each queue is also different, and the higher the priority queue, the smaller the elapsed time slice for each process. For example, the time slice of the 2nd-level queue is one-fold longer than the time slice of the 1th-level queue ... The time slice of the i+1 queue is one-fold longer than the time slice of the class I queue.

(3) when a new process enters memory, it is first placed at the end of the 1th level 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 transfers the process to the end of the 2nd level queue, and then similarly waits for dispatch execution according to the FCFS principle, if it is not completed after running a time slice in the 2nd In the same way into the 3rd level queue ... In this way, when a long process is descending from the 1th level to the nth queue, it is run in the nth queue in a time-slice rotation.

(4) only when the 1th-level queue is empty does the scheduler dispatch the processes in the 2nd-level queue, and the processes in the level I queue are dispatched only if the 1th-(i-1)-level queue is empty. If the processor is performing a process in the Class I queue, and a new process enters a queue with a higher priority (1th ~ (i-1) Any one of the queues), 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 class I queue. Assign the processor to the new higher-priority process.

The advantages of multi-level feedback queues are:

① terminal type job User: Short job first.

② short batch job User: Turnaround time is short.

③ Long batch job users: Some of the previous queues have been partially executed and will not be processed for long periods of time.

This article from the "Chase" blog, reproduced please contact the author!

Common scheduling algorithms for operating systems

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.