There are several reasons for process scheduling:
When does process scheduling happen? This is related to the cause of process scheduling and the method of process scheduling.
(1) the process being executed is completed. At this time, if you do not select a new ready process for execution, it will waste processing resources.
(2) the execution process calls the blocking primitive to block itself into sleep and other States.
(3) In the execution process, the P primitive operation is called and thus blocked due to insufficient resources; or the v primitive operation is called to activate the process queue waiting for resources.
(4) The process is blocked after an I/O request is submitted.
(5) the time slice has been used up in the time-sharing system.
(6) When a user process is returned after a system program such as a system call is executed, the system process is deemed to have been executed, so that a new user process can be selected for execution.
All of the above are the causes of process scheduling in the case of deprivation. When the CPU execution method is denied
(7) The priority of a process in the ready queue is higher than that of the currently executed process, which also triggers process scheduling.
Two CPU usage methods
Detachable (preemptive): If a process with a higher priority than the current execution process has exists in the ready queue, process scheduling occurs immediately and the processor is transferred.
Non-Intrusive (non-preemptive): even if the ready queue has a higher priority than the current execution process, the current process will still occupy the processor until the process itself enters the blocking, sleep state due to calling the primitive operation or waiting for I/O, or re-scheduling occurs only when the time slice is used up.
For kernel threads, the scheduling objects in the kernel are threads. for user threads, the kernel uses processes as scheduling objects rather than user threads. User threads are implemented in the user space, the kernel does not directly schedule user thread processes. The scheduling object of the kernel is a process, and the kernel does not know the existence of user threads.
In linux kernels, kernel threads are usually called Kernel processes. When a kernel thread is in the blocking state, other kernel threads or kernel processes are not affected, A user thread in a user process is blocked, which will cause the process to sleep.
Supplement: when a process is blocked, the kernel thread is included. The process is suspended and the suspended process enters the sleep state. When a spin lock fails to be obtained, it does not block. Instead, it checks whether resources can be obtained in an endless loop,
Loop wait does not mean blocking.
A blocking operation means that when a device operation fails to obtain the resource, the process suspends until the operation meets the operational conditions.
This article from the "Yi fall Dusk" blog, please be sure to keep this source http://yiluohuanghun.blog.51cto.com/3407300/1304572