Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Simple understanding of Linux process scheduling

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

I. R, S, D, T, Z, X status of the Linux process

R (TASK_RUNNING): the process is in the ready state and executable state

S (TASK_INTERRUPTIBLE): a sleep state that can be interrupted

D (TASK_UNINTERRUPTIBLE): uninterrupted sleep, rarely seen

T (TASK_STOPPED or TASK_TRACED): paused or tracked status, received sigstopt signal becomes paused, received sigcont becomes running status; gdb debugging and tracking status

Z (TASK_DEAD-TASK_ZOMBIE): exit status, the process is called a zombie process (child process exits)

X (TASK_DEAD-EXIT_DEAD): exit status, process is about to be destroyed (one process cancel another)

In normal work, R and S are the most common, when the process accepts message queues, sleep, etc., the process is in a blocking state (S).

General state change, R, R, S, M, S, R, R

View the process status s (state) column through ps-l

2. Linux provides two priorities: normal process priority and real-time process priority.

1. Real-time process priority

There are two scheduling algorithms for real-time priority: SCHED_FIFO (first-in first-out scheduling algorithm) and SCHED_RR (time slice polling scheduling algorithm)

Real-time priority scheduling features: only static priority, will not adjust the priority, the default priority is 0-99 (MAX_RT_PRIO=100). The nice value only affects the process priority of 100-100-40.

Summary: for FIFO, it is only when the process is finished that it is another process's turn to execute.

For RR, once the time slice is exhausted, the process is placed at the end of the queue so that other processes can execute.

2. General process priority

General priority scheduling algorithm: SCHED_NORMAL (CFS Scheduler implementation)

General priority scheduling characteristics: according to dynamic priority scheduling, dynamic priority is adjusted by static priority. The static priority is hidden by the kernel, but provides an interface: calculated from the nice value:

Static_prio = MAX_RT_PRIO (default 100) + nice + 20

Nice ranges from-20 to 19, so the static priority is 100 to 139.

And the process time slice also has a static priority:

If (static_prio

< 120 ) time = ( 140 - static_prio )*20else if( static_prio >

= 120) time = (140-static_prio) * 5 two main factors to be considered in dynamic priority: static priority and average running time of the process bouns value, calculation formula:

Dynamic_prio = max (100min (static_prio-bouns+5, 139)

The size of the bouns value is 0-10. When it is greater than 5, the priority is increased, and when it is less than 5, the priority becomes lower. The Linux kernel dynamically changes the dynamic priority of the process according to the average running time of the process.

In general, the average running time of interactive processes is long, so the Linux kernel rewards to increase the value of bouns.

Summary: real-time processes only consider static priorities; ordinary processes generally don't need to care too much about process priorities, because the kernel dynamically adjusts the priorities of processes.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report