Multi-task operating systems can be divided into non preemptive multitasking and preemptive multitasking. Like most modern operating systems, Linux also uses preemptive multitasking mode. This means that the time the task takes CPU is determined by the scheduler.
Scheduling policy:
Deciding when and how to choose a new process on which CPU to run for how long is called a scheduling policy.
Typically, what scheduling policy is used is related to the type of process. Processes are often divided into CPU consumption and IO consumption types.
Another type of classification is:
1, interactive process (interactiveprocess): Such processes require a large number of human-computer interaction, such a process will continue to sleep, waiting for keyboard and mouse operation to wake it up. Such processes require a high response time for the system. A typical process, such as a text-editing program.
2. batch processing (batch process): Such processes do not require human-computer interaction, often in the background process, can endure the slow response, such as compilers.
3. Real-time processes (real-time process): Such processes require a high response time for the system. such as video audio playback software.
Note: In order to correspond to real-time processes, interaction processes and batch processes are often referred to as common processes.
Policy flags:
Sched_normal: The default scheduling strategy, named Sched_other in the old version, time-sharing scheduling strategy
Sched_batch: for batch processes.
Sched_idle: Processes that use this scheduler have the lowest priority. Introduced in the implementation of CFS.
Sched_fifo: Advanced first out strategy for real-time processes. Once the CPU is occupied, it continues until a higher priority process or itself discards the CPU. Suitable for a process with high time requirements, short each time running.
SCHED_RR: A time slice rotation strategy for real-time processes. When the time slice of the process is exhausted, the system assigns it a time slice and places it at the end of the queue. This allows each process to run for a period of time. Applies to processes that take longer to execute each time.
Summary: Sched_normal,sched_batch,sched_idle: Both are used with ordinary processes. Difference: Sched_normal is the default scheduling policy. Sched_batch is used with batch processes. Sched_idle is used for the lowest-priority background program. Sched_normal and Sched_batch Beg to differ only when awakened. Waking a more frequent process is not suitable for sched_batch. The scheduling strategy used by the process is reflected in the policy, whose value is the value above. The child process inherits the policy of the parent process. At the same time, we can modify it by Sched_setscheduler.
All tasks are based on the Linux time-sharing scheduling strategy.
1, create tasks Specify a time-sharing scheduling policy and specify the priority nice value ( -20~19).
2, the execution time on the CPU (counter) is determined based on the nice value of each task.
3, if the resource is not waiting, the task is added to the ready queue.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/unix/