Operating system learning-CPU scheduling (2)

Source: Internet
Author: User

CPU scheduling, multi-channelProgramThe basis of the operating system.

The computer's throughput refers to the number of processes processed by the computer per unit of time.

CPU scheduling improves the computer throughput by switching the CPU between processes.

We know that the execution of processes includes CPU execution and I/O wait cycles. The process must be continuously switched under these two statuses.

CPU scheduling is generally described in the following four situations:

(1) When a process switches from running to waiting;

(2) When a process switches from running to ready;

(3) When a process switches from the waiting state to the ready state;

(4) when the process is terminated;

For the above four cases, only the process selection problem exists in the (1) and (4) cases, and a new process must be selected for execution.

There are a lot of CPU schedulingAlgorithmThe specific effects of different scheduling algorithms are as follows:

(1) CPU utilization. We need the CPU to be used as high as possible.

(2) throughput. The number of processes that a computer can complete in a unit of time.

(3) turnaround time. The time required for a process from submission to final execution is called the turnaround time.

(4) wait time. The time that a process spends waiting in the ready queue.

(5) response time. It refers to the time from the process to the first response.

The following describes common CPU scheduling algorithms.

(1) first come first served scheduling algorithm (FCFS, first-come first served)

As the name implies, it is the person who runs the task first. This algorithm is not preemptible, that is, once the CPU is assigned to a process, you must wait until the process is terminated or enters the waiting state to release the CPU and allocate it to other processes. For this scheduling algorithm, if the first process is a process that requires a long CPU interval, several processes with short CPU Interval Length will be followed, these short processes can only be executed after the long process is executed. Because the process is not preemptible, the average wait time will be long.

(2) Shortest-job-first, SJF)

To solve the problem mentioned above, we can use the shortest job to prioritize scheduling. This type of scheduling is a type of priority scheduling, which is based on the length of the CPU range. This scheduling algorithm always gives priority to processes with the shortest CPU Interval Length. The difficulty of this algorithm is to know the length of the next CPU range. SJF is often used for long-term scheduling.

(3) Priority Scheduling (Priority Scheduling Algorithm)

Priority Scheduling is to assign a priority level to each process. High-priority processes are executed before low-priority processes. processes with the same priority are scheduled using the FCFS scheduling algorithm. Priority Scheduling can be preemptible or non-preemptible. After a process reaches the ready queue, it will be compared with the priority of the running process. If the priority of the new process is higher than that of the running process, the preemptible priority scheduling will seize the CPU, instead of preemptible priority scheduling, the new process is added to the header of the ready queue. One of the main problems of priority scheduling is infinite congestion or hunger. Because low-priority processes may not be executed. The solution to this problem is aging. Aging is a technology used to continuously improve the priority of processes that have a long wait time in the system. This allows the process to be executed.

(4) Round Robin Scheduling (round-robin scheduling algorithm)

Rotation scheduling is specially designed for time-sharing systems. This scheduling algorithm introduces the concept of time slice. The time slice generally ranges from 10 to 10 ~ 100 ms. Design the ready queue as a cyclic queue. The scheduling algorithm cyclically traverses every process in the ready queue and assigns a time slice to each process. If the process is completed in the time slice, it traverses the next process in sequence, if the process in the time slice is not completed, add the process to the end of the ready queue and switch the context to the next process in the ready queue for execution. The performance of the rotation scheduling algorithm depends largely on the size of the time slice. Generally, the length of the time slice is greater than the context switching time, but it cannot be too large, otherwise, the rotation scheduling will be converted to the FCFS scheduling algorithm.

(5) Multi-Level queue Scheduling

According to the different scheduling needs of different processes, we can divide the ready queue into several independent queues, each of which has its own scheduling algorithm.

(6) Multi-Level feedback queue Scheduling

In a multi-level queue scheduling algorithm, a process is assigned to a queue, Which is permanent and cannot be transferred from one queue to another. The advantage of this setting is that the scheduling overhead is low, but not flexible enough. The opposite is the multi-level feedback queue scheduling algorithm, which allows the process to move between queues. The idea is that when a process uses too much CPU time, it will be transferred to a lower priority queue. Processes that wait for a long time in a lower-priority queue will be transferred to a higher-priority queue to prevent infinite blocking or hunger.

So far, I think you have some knowledge about CPU scheduling. To learn more, you have to read your own books...

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.