Fundamentals of Computer Operating System (6) --- Process Scheduling of Job Management

introduction

This article is the sixth chapter, the process scheduling of job management , this article mainly introduces the overview of process scheduling and the algorithm of process scheduling

1. Overview of process scheduling

Process scheduling means that the computer decides which ready process can get the CPU usage right through decision-making . In other words, process scheduling refers to which process the computer chooses to use the CPU, provided that the state of the process is ready

There are two steps to process scheduling:

  • Keep the running information of the old process, please remove the old process
  • Select a new process, prepare the running environment and allocate CPU

In order to achieve these two steps of process scheduling, you need to understand three important mechanisms:

  • The queuing mechanism of the ready queue
  • Select the delegation mechanism for running processes
  • Context switching mechanism for new and old processes

The queuing mechanism of the ready queue

(1) The queuing mechanism of the ready queue

All processes in the ready state are placed in the ready queue

The queuing mechanism of the ready queue is to improve the efficiency of process scheduling. The ready processes are queued in a certain way in advance so that the scheduler can find the ready process as soon as possible

(2) Select the delegation mechanism of the running process

This mechanism requires that a process can be selected from the ready queue and then sent to the CPU for execution. The scheduler selects the ready process with a certain strategy and allocates CPU resources to it

(3) Context switching mechanism for new and old processes

If you want to schedule a new process to the CPU, you need to back up the CPU environment of the old process , and then switch the CPU environment of the new process. It saves the context information of the current process and loads the running context of the delegated execution process

There is a cache in the CPU . This mechanism is to first back up the context of the old process to the main memory, and then put the context of the new process into the CPU to prepare the environment so that the new process can run. This is the new The online text switching mechanism of the old process. These three are the three basic mechanisms required for process scheduling

Consider a question. What should I do if the old process has not been executed when scheduling is performed?

According to whether the old process has been executed, the process scheduling methods are divided into two categories:

  • Non-preemptive scheduling
  • Preemptive scheduling

Non-preemptive scheduling

  • Once the CPU is allocated to a process, let the process continue to use
  • The scheduler does not preempt the CPU being used for any reason
  • The CPU will not be released until the process finishes its work or because of IO blocking

Preemptive scheduling

  • Allow the scheduler to suspend the currently running process with a certain strategy
  • Save the context information of the old process and allocate CPU to the new process

Two ways to make a comparison

Algorithm for process scheduling

  • First come first serve scheduling algorithm
  • Short process priority scheduling algorithm
  • High priority priority scheduling algorithm
  • Time slice round-robin scheduling algorithm

First come first serve scheduling algorithm

In the ready queue, according to the principle of first come, first served, priority is given to the process in front of the queue for scheduling

Short process priority scheduling algorithm

  • The scheduler preferentially selects the process with the shortest estimated running time in the ready queue
  • Short process priority scheduling algorithm is not conducive to the execution of long job processes

High priority priority scheduling algorithm

This algorithm is based on priority

  • Processes have priority, and the scheduler prefers processes with higher weights
  • High priority priority scheduling algorithm allows urgent tasks to be processed first

As mentioned in the previous article, the priority of the foreground process is higher than the priority of the background process, because the foreground process interacts with the user. In order to ensure that the user will not be stuck when using the system, the weight of the foreground process must be Higher than background process

Time slice round-robin scheduling algorithm

Arrange ready processes on a first-come, first-served basis

Every time a process to be executed is taken out from the head of the queue , a time slice is allocated for execution (the time slice is used up, regardless of whether the process has been executed or not, the process will be re-inserted to the end of the queue . The time allocated for each process The film is the same). It is a relatively fair scheduling algorithm, but it cannot guarantee timely response to users

It is the core competitiveness of a technical person to find the constant in the rapidly changing technology. Unity of knowledge and action, combining theory with practice

Standing on the shoulders of giants and learning, paying tribute to the predecessors

Reference: https://coding.imooc.com/class/355.html

Guess you like

Origin blog.csdn.net/self_realian/article/details/107016346