Process Scheduling dynamically allocates the CPU to each process. The main functions are as follows:
(1) Remember the Process status.
(2) decide which process, when to obtain the CPU and how long it takes.
(3) Allocate the CPU to the process, that is, information about the process in the PCB of the selected process, such as the Program Status Register and general register, to the corresponding registers of the CPU, so that the process consumes CPU to run.
(4) reclaim the CPU.
Various opportunities for starting the process scheduler:
(1) After an external interrupt, the interrupt changes the status of a process.
(2) After an information call, the current process cannot continue to run.
(3) After an error is handled, the current process will be blocked during error handling.
Scheduling Policy:
(1) Time-Based System Call Policy
In the time-sharing system, in order to improve the interaction response speed and enable each process to occupy the CPU Within a short interval, You need to schedule the CPU more frequently. This scheduling method increases the system overhead and reduces the actual CPU usage efficiency. For example, in order to ensure timely response, the rotation algorithm is used to allocate the CPU, that is, to request a time slice for each user in a cyclical manner, which is also the origin of "time-sharing. The role of this operation is to prevent the user from monopolizing the CPU when computing tasks that take a long time, and impede the response to service requests from other users. The average CPU usage is used. However, if the time slice is too large, the corresponding average response time increases. If the time slice is too short, the number of service request cyclic queues increases, therefore, the average response time is increased, and the system overhead is also increased due to frequent switching. Therefore, considering the main purpose of system time-sharing. The efficiency of system resources should be improved on the premise of meeting the response speed of a certain interaction.
(2) scheduling policy of the batch processing system
1. Service algorithms first:
First, service algorithms reflect user fairness. The scheduling policy allocates the CPU according to the priority. The priority value is determined by the timestamp of all processes. It gives priority to the thread with the longest wait time in the system, regardless of the running time of the process. This algorithm is generally a non-preemptible scheduling algorithm, that is, once a process is allocated a CPU, it will continue until the operation ends.
2. shortest job Priority Scheduling Algorithm:
This algorithm always takes priority when scheduling processes with the lowest running time as the object of the next service. It can achieve the maximum throughput of the system. Its main drawback is that it only takes care of short processes. Therefore, it is possible that after a process enters the system, the process will not be ready to run due to the constant entry of processes shorter than it.
3. Priority Scheduling Algorithm for high response ratio:
This algorithm calculates the Response Ratio of each process in the backup schedule during each scheduling, and then selects the highest response ratio for running. Therefore, the process in the system only needs to wait for a long enough time to run. This algorithm takes into account the waiting time and takes into account the priority of short job processes. It is a compromise between the two algorithms. The disadvantage is that the algorithm is complex, and the Response Ratio of each process in the backup process queue must be calculated for each scheduling.
(3) Real-Time System Scheduling Policy
For real-time systems that require the CPU to respond in a timely manner, it is mainly used to implement specific control and service functions. Set a priority value for each process. During CPU scheduling, select the priority value of the ready process each time, so that it consumes CPU to run.
(4) General System Scheduling Policies
1. Priority number algorithm.
2. Round forwarding.
3. Variable time slice forwarding and multi-queue rotation.