Operating system-process scheduling

The function of process scheduling: It is completed by the process scheduler of the operating system kernel. In the Linux kernel, the function of process scheduling starts from calling the kernel function schedule().

What is the scheduling function of the operating system?

According to a certain strategy or algorithm, a new thread to run on the current CPU is selected from the ready state process.

Guidelines for choosing the appropriate scheduling algorithm?

The turnaround time is short, the response time is fast, the deadline is guaranteed, the system throughput is high, and the processor (CPU) utilization rate is good.

Scheduling Algorithm

The scheduling algorithm is divided into:

First-come, first-served scheduling algorithm (FCFS) : As the name suggests, first-come, first-served, which process arrives in the ready queue first, allocates CPU for which process first.

Performance analysis: suitable for long processes, not conducive to short processes. Conducive to CPU busy processes, not conducive to (I/O) busy processes.

Short Process Priority Scheduling Algorithm (SPF) : Select the process with the shortest estimated running time from the ready queue, assign CPU first, and execute it first.

Performance analysis: Advantages: Compared with the FCFS algorithm, the short-process-first algorithm can effectively reduce the average waiting time of the process and improve the throughput rate of the system.

Disadvantages:

1. It is not good for the long process. If a short process enters the system all the time, the long process cannot be scheduled.

2. There is no guarantee of timely handling of urgent processes.

3. The length of the process is determined according to the user's estimation, so it may not be possible to give priority to the real short process.

Priority scheduling algorithm : A system using priority scheduling algorithm, each process has a priority associated with it. Priority is usually a fixed number, such as a number from 0 to 127. The system may be designed such that the higher the priority, the higher the priority. The system assigns the CPU to the process with the highest priority value in the ready queue.

Priority scheduling algorithm type:

1. Non-preemptive: If the CPU is running a process, and then a process with a high priority comes in the ready queue, then wait for the current CPU to finish executing the current process, and then execute the incoming process with the high priority, without preempting CPU.

2. Preemptive type: Contrary to the above, directly preempt the CPU and execute the incoming process with high priority.

Priority category:

Dynamic priority: The process is given priority when it is created, and it changes as the process progresses or the waiting time increases.

Static priority: It is determined when the process is created and remains unchanged during the entire running period of the process.

Time slice rotation scheduling algorithm (RR) : Design a time slice, which is the time a process runs on the CPU. Generally, there are two situations. One is that the time slice is not used up and the process ends and the CPU is automatically released. The other is the case where the time interval of the process is greater than one time slice, and the process may require several time slices. Whenever the continuous running time of a process on the CPU is equal to the length of a time slice, the operating system will preempt the CPU during the clock interrupt processing, perform process switching, replace the current process with the new ready process, and return to the replaced current process In the ready queue.

Factors to consider when determining the time slice size: 1. The system's requirements for response time. 2. The number of processes in the ready queue. 3. The processing capacity of the system.

Performance analysis: The performance of the RR algorithm largely depends on the size of the time slice. In extreme cases, the time slice is large, it will be the same as the first-come, first-served algorithm. If it is small, the process needs to go through multiple context switching and process scheduling, which wastes time and increases the overhead of the CUP in switching processes and process scheduling.

 

Guess you like

Origin blog.csdn.net/weixin_44126152/article/details/106679822