The concept of process scheduling-General Linux technology-Linux programming and kernel information. The following is a detailed description. Linux is a time-sharing system. The Kernel divides each process into a time slice. when the time slice of the process is used up, another process is scheduled to run. The scheduling program on LINUX system is a multi-level feedback loop scheduling. The scheduling method is to split a process into a time slice to take the lead of a process that exceeds the time slice and feed the process back to a queue in several priority queues. Before the process is executed, it must go through such multiple feedback cycles.
Process Scheduling is divided into two parts: one is the scheduling time, that is, when scheduling; the other is the scheduling algorithm, that is, how to schedule and which process to schedule. Let's take a look at the scheduling algorithm. assuming that the current kernel requires scheduling, the scheduler selects a process with the highest priority from the processes in the "ready in memory" and "preemptive" states, if there are several processes with the same priority, select the process with the longest waiting time. Switch the process context and continue executing the process. If no process is selected, no operation is performed. wait for the next scheduling time.
Each process has a priority domain for scheduling. Process Priority is roughly divided into user priority and kernel priority from low to high. Each priority value corresponds to several priority values. Each priority has a process queue logically connected to it. The process is preemptible when it returns from the kernel status to the user status to obtain the user priority. The process obtains the kernel priority in the kernel algorithm sleep. Kernel priority is higher than user priority, that is, there is a threshold between kernel priority and user priority. all user priority is lower than this threshold, and kernel priority is higher than this threshold. Kernel priority is classified as interrupted and non-disruptive. that is, when a process receives a soft interrupt signal, the process with a low kernel priority can be awakened, and the process with a high kernel priority can continue to sleep.
The time to calculate the priority of a process is that the kernel assigns a priority value to a process that will enter sleep, which is fixed and associated with the cause of sleep. The other time is, the clock handler adjusts the priority of all processes in the user state at a certain time (such as every one second) and enables the kernel to run the scheduling algorithm. The clock processing program also adjusts the recent CPU usage time of each process once per second based on an attenuation function. For example, you can adjust it according to the following formula:
Decay (CPU) = CPU/2;
Then, calculate the priority value of each process in the "ready" and "preemptive" statuses based on the formula.
Priority = ("recent CPU usage"/constant) + (base priority) + (nice value );
Here, constant is a system constant (generally the value is "2 "). The base priority value is also a constant of the system. Generally, the base priority value is 60. Finally, the nice value is the value given by the process when it sends a nice call, so that the user can get some execution time by reducing the priority. Only super users can specify nice values for priority improvement.
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