Process scheduling algorithm

Source: Internet
Author: User

One, the task of process scheduling

(1) Save the site information of the processor. In the scheduling of the first to save the current processor's field information.

(2) Select the process according to an algorithm. The scheduler chooses the process according to an algorithm, changes its state to a running state, and prepares to assign the processor to it.

(3) Assign the processor to the process. The dispatcher assigns the processor to the process, at which point the process control block of the selected process needs to be loaded into the corresponding registers of the processor, and the control of the processor is given to the process so that it recovers from the last power outage.

Second, process scheduling algorithm

    1. Rotation scheduling algorithm

The algorithm employs a deprivation strategy. Let the ready process in a fcfs manner in a time-slice rotation of the CPU scheduling, the system will be all ready process in accordance with the FCFS principle, a queue, each time scheduling the CPU to the team first process, let it execute a time slice, the length of the time slice from a few ms to hundreds of Ms. At the end of a time slice, a clock interrupt occurs, where the scheduler pauses the execution of the current process, sends it to the end of the ready queue, and executes the current team first process through a context switch, and the process can sell the CPU (such as blocking) without using a time slice. Time-slice rotation scheduling algorithm is characterized by simple and short average response time, but it is not conducive to emergency operation.

Obviously, the rotation method can only be used to dispatch some resources that can be preempted. These resources can be preempted at any time and can be reassigned to other processes. CPU is one of the resources that can be preempted. But the printer and other resources are not preemptive. Because job scheduling is the allocation of all system hardware resources except the CPU, which contains non-preemptive resources, job scheduling does not use a rotation method. In the rotation method, the selection of time slice length is very important. First, the choice of time slice length directly affects the overhead and response time of the system. If the time slice length is too short, the dispatcher preemption processor more times. This will significantly increase the number of process context switches, thereby aggravating the system overhead. Conversely, if the time slice length is chosen too long, for example, a time slice can guarantee that the process that takes the longest execution time in the ready queue can be completed, the rotation method becomes the first-come-first service method. The choice of time slice length is determined by the system's response time requirements and the maximum number of processes allowed in the ready queue.

In the rotation method, there are 3 scenarios for joining the ready queue, one for which the time slice is used up, but the process is not completed, and the next schedule is returned to the end of the ready queue for execution to continue. Another scenario is that the time slices that are assigned to the process are not exhausted, only because the request I/O or the mutex and synchronization relationships of the process are blocked. When the blocking is lifted, return to the ready queue. The third scenario is that the newly created process enters the ready queue. If these processes are treated differently, giving different priorities and time slices, intuitively, can further improve the quality and efficiency of system services. For example, we can divide the ready queue into different ready queues according to the type of process arrival readiness queue and the blocking reason when the process is blocked, each queue is arranged according to FCFS principle, the processes between each queue have different priority, but the same queue has the same priority. Thus, when a process finishes its time slice, or is awakened from sleep and created, it enters a different ready queue.


2. Priority scheduling algorithm

In the time-slice rotation scheduling algorithm, it makes an implicit hypothesis that all process time urgency is the same in the system. However, in order to meet the actual demand, the priority is introduced in the process scheduling algorithm, and the priority scheduling algorithm is formed.

Priority scheduling algorithm core is to determine the priority of the process. First, the system or user assigns a priority to the process in a way that represents the scheduling priority that the process enjoys. There are many methods to determine the priority, which can be divided into two kinds, static and dynamic method. Static methods determine their priority based on the static nature of the process before the process starts executing, and cannot be changed once the execution has started. Dynamic Law Otherwise, it combines the static and dynamic characteristics of the process to determine the priority of the process, and its priority changes as the process executes.

The most basic way to determine the static precedence of a <1> process is to give different priorities according to the type of process. For example, in some systems, processes are divided into system processes and user processes. The system process has a higher priority than the user process, and for the user process, it can be divided into: I/O busy processes, CPU busy processes, I/O and CPU balanced processes and other processes.

The scheduling algorithm based on the static priority is simple and the system overhead is small, but the system is inefficient and the scheduling performance is not high because once the static priority is determined, it remains unchanged until the end of execution. In the current operating system, if the use of priority scheduling, then most of the use of dynamic priority scheduling strategy.

The dynamic priority of the <2> process can generally be determined according to the following two aspects:

(1) Depending on the length of the CPU time the process occupies. The longer a process takes possession of a processor, the lower the priority to get the dispatch again after it is blocked. Conversely, the probability of its scheduling will be greater.

(2) Depending on the length of time the ready process waits for the CPU to be determined. The longer a ready process waits in the ready queue, the higher the priority it gets scheduled to be selected.

Because the dynamic priority changes over time, the system often calculates the priority of each process, so the system has to pay a certain amount of overhead.

The priority priority scheduling algorithm is better for multi-channel batch processing system, but it makes the process wait longer for lower priority, which is not allowed to get better response time in time-sharing system, so it is used to process scheduling by using the temporal slice rotation method.


3. Multi-Queue scheduling algorithm

In the process scheduling, because the system set up a process of the ready queue, that is, the low-level scheduling algorithm is fixed, a single, can not meet the different users of the system process scheduling policy requirements, in the multiprocessor system, this single scheduling policy implementation of the shortcomings of the mechanism is more prominent, The multi-queue scheduling algorithm can compensate for this shortcoming to some extent.

The algorithm splits a process-ready queue in a system into several. Processes with different types or properties are assigned differently in different ready queues, different ready queues have different scheduling algorithms, and processes in the ready queue can have different priorities. Therefore, the system is easy to provide a variety of scheduling strategies for the needs of different user processes.

4. Multilevel Feedback Queue scheduling algorithm

The multi-level feedback queue scheduling algorithm does not need to know beforehand the execution time of various processes, but also can satisfy the needs of various types of processes, so it is now recognized as a good process scheduling algorithm.

(1) set up multiple ready queues . Set up multiple ready queues in the system 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) The FCFS algorithm is used for each queue . 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) scheduling by queue priority . 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.

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/82/8E/wKioL1daYZuBiNREAAA4zrnu89c703.png-wh_500x0-wm_3 -wmp_4-s_2728578321.png "title=" capture. PNG "alt=" Wkiol1dayzubinreaaa4zrnu89c703.png-wh_50 "/>



This article is from the "Shuoyuexinmao Cloud" blog, please be sure to keep this source http://19940325.blog.51cto.com/10789287/1787769

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.