Summary of process scheduling algorithm

Source: Internet
Author: User

The so-called process, which is simply a variety of tasks in the computer, how does the computer allocate system resources for these tasks to use? The purpose of this blog is to tidy up several common process scheduling algorithms for everyone.

Scheduling is the process of dynamically assigning a processor to a ready queue and executing it according to a certain strategy.

A common process scheduling algorithm:

1, first come first service and short job (process) Priority scheduling algorithm

2. High priority priority scheduling algorithm

3. Rotation scheduling algorithm based on time slice

The following is an elaborate:

1, first come first service and short job priority scheduling algorithm

1.1, first come first service scheduling algorithm

This scheduling algorithm by the literal meaning understanding is very intuitive, so-called first to first service, is who first to serve who first. In conjunction with a process, a first-come-first service scheduling algorithm is a policy that takes precedence over the priority of a process that arrives at the ready queue until the process finishes running or an event causes blocking to abort the processor. This scheduling algorithm is one of the simplest scheduling algorithms, which is suitable for jobs and processes. When used for a job, the job that first enters the fallback queue runs first.

1.2. Short job (process) Priority scheduling algorithm

short Job (process) Priority scheduling algorithm is a scheduling algorithm for short or short processes. What is short? is to estimate the running time is short. The algorithm chooses a job or process that estimates a shorter run time from a fallback queue or a ready queue, moves them into memory until the process finishes running, or an event causes blocking to abort the processor rescheduling.

2. High priority priority scheduling algorithm

2.1. Priority scheduling algorithm

The above mentioned two scheduling algorithms, too simple, when there are urgent jobs or processes in the system, and do not meet the advanced queue or short running time, these jobs or processes will be difficult to obtain resources. What about these jobs or processes? Therefore, there is a priority scheduling algorithm, the so-called priority scheduling algorithm, as the name implies is who priority high, who will get resources to run XI ' an. The algorithm is further divided into the following two types:

2.1.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.1.2, preemptive priority 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.

2.2, high response ratio priority scheduling algorithm

Two formulas are explained before the introduction:

It can be seen from the above formula:

(1) If the waiting time of the job is the same, the shorter the service time, the higher the priority, so the algorithm is advantageous to the short job.

(2) When the time required for the service is the same, the priority of the job depends on its waiting time, the longer the waiting time, the higher the priority, so it realizes the first to first service.

(3) For long jobs, the priority of the job can increase with the waiting time, and when its waiting time is long enough, its priority can be raised to high, thus also can obtain the processor. Therefore, the algorithm realizes a good tradeoff. Of course, when using this algorithm, the response ratio calculation must be done before each dispatch, which increases the system overhead.

3. Rotation scheduling algorithm based on time slice

3.1. Time slice Rotation method

In the early time-slice rotation, the system queues up 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.

3.2. 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 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.

Summary of process scheduling algorithm

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.