Process scheduling algorithm

Source: Internet
Author: User

In the system, the number of user processes is generally more than the number of processors, which will cause them to compete with each other processor. In addition, the system process also needs to use the processor. This requires the process scheduler to dynamically assign the processor to a process in the ready queue for execution, according to a certain strategy.

Process scheduling Tasks

(1) First to save the current process of the processor's field information

(2) Follow the algorithm selection process

(3) Assign the processor to the process. (In the Process control block of the selected process, the information about the field of the processing machine is loaded into the corresponding register, and the process controls the processor so that it resumes operation from the last breakpoint)

First , first come service and short job (process) priority scheduling algorithm1. First come first service scheduling algorithm

Assign the CPU according to the order in which the job submission or process becomes ready;

The current job or process consumes the CPU until it is executed or blocked before the CPU is sold (not preempted).

After a job or process wakes up (such as I/O completion), it does not immediately resume execution, usually until the current job or process has transferred the CPU.

"Suitable Use the scene :

It is better for long work than for short work. Because long operation takes time to occupy the processor.

It is advantageous to the CPU busy job, but is not conducive to the I/O busy job.

2. Short job (process) Priority scheduling algorithm

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 . The main disadvantage is that long-running operations cannot be guaranteed.

second, high priority priority scheduling algorithm

1. Types of priority scheduling algorithms

The highest priority priority (FPF) scheduling algorithm is introduced in order to take care of the urgent operation, so that it gets preferential treatment after entering the system. This algorithm is often used in batch processing system , as a job scheduling algorithm, also as a process scheduling algorithm in a variety of operations, can also be used in real-time systems. When the algorithm is used for job scheduling, the system will select several of the highest priority jobs from the fallback queue to load the memory. When used for process scheduling, the algorithm is to assign the processor to the ready queue of the highest priority process , at this time, the algorithm can be further divided into the following two kinds.

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 is executed until it is completed, or the process is discarded due to an event , the system can then The processor is reassigned to another process with the highest priority . 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.

2. 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:

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:

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, and therefore 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 serve first.

Three, time-slice-based rotation scheduling algorithm

1. Rotate (round robin. RR) Scheduling algorithm

In the time-sharing system, the simplest and most commonly used is the temporal slice of the rotation scheduling algorithm, the algorithm uses a very fair processor allocation method, that is, each process on the ready queue to run only one time slice.

Fundamentals of the > Rotation method

The system queues all ready processes into the ready queue by FCFS policy. The system generates a break at intervals, activates the process scheduler to dispatch, allocates the CPU to the team's first process, and makes it perform a time slice

If a time slice is not exhausted, the process completes and immediately activates the scheduler, removing him from the ready queue.

If a time slice is exhausted, the timer interrupt handler is activated and the scheduler takes it to the end of the ready queue.

"Time Slice length determination:

Effect of time slice length change

The degradation is FCFS algorithm, the process is executed within a time slice, and the response time is long.

A request for a user that is too short requires multiple time slices to be processed, the number of context switches increases, and the response time is long.

The size of a more desirable time slice is slightly larger than the time required for a typical interaction, and most interactive programs can be completed within a single time slice.

Response Time Requirements: T (response time) =n (number of processes) *q (time slice)

Number of ready processes: The more the number, the smaller the time slice

The processing power of the system: the user input should usually be processed within one time slice, otherwise the response time, the average turnaround time and the average time of the cycle is extended.

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

Advantages:

  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 reduced response time.

No need to estimate process execution time, dynamic tuning

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.