linux性能分析优化之基础指标参数(1) - Process Status | 进程状态

查看方式

top命令

top命令中S那一列。即下图中SHR后面%CPU前面那一列。下图中的sshd进程和systemd进程的S列都处于S状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$top

top - 22:49:54 up 2 days, 11:50, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 142 total, 1 running, 141 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 8043696 total, 174212 free, 105000 used, 7764484 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 7574668 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
15460 ubuntu 20 0 93072 5216 4028 S 0.3 0.1 0:00.04 sshd
1 root 20 0 37688 5212 3460 S 0.0 0.1 0:03.50 systemd
.
.
.
ps命令

ps命令中STAT那一列。下图中systemd进程为Ss,[kthreadd]为S

1
2
3
4
5
6
7
8
$ps aux

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 37688 5212 ? Ss Apr24 0:03 /lib/systemd/systemd --system --deserialize 19
root 2 0.0 0.0 0 0 ? S Apr24 0:00 [kthreadd]
.
.
.

含义

top文档中的描述
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
3a. DESCRIPTIONS of Fields
20. S -- Process Status
The status of the task which can be one of:

D = uninterruptible sleep
R = running
S = sleeping
T = stopped by job control signal
t = stopped by debugger during trace
Z = zombie


Tasks shown as running should be more properly thought of as ready to run --
their task_struct is simply represented on the Linux run-queue. Even without
a true SMP machine, you may see numerous tasks in this state depending on top's
delay interval and nice value.

A process in a runnable state is either using the CPU or waiting to use the CPU.
A process in uninterruptable state is waiting for some I/O access, eg waiting for disk.
ps文档中的描述
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PROCESS STATE CODES
Here are the different values that the s, stat and state output specifiers
(header "STAT" or "S") will display to describe the state of a process:

D uninterruptible sleep (usually IO)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped by job control signal
t stopped by debugger during the tracing
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z defunct ("zombie") process, terminated but not reaped by its parent

For BSD formats and when the stat keyword is used, additional characters may be displayed:

< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group
资料

In linux, what do all the values in the “top” command mean? - Stack Overflow - answered by CesarB

‘S’ and ‘D’ are two sleep states, where the process is waiting for something to happen. The difference is that ‘S’ can be interrupted by a signal, while ‘D’ cannot (it is usually seen when the process is waiting for the disk).

‘T’ is a state where the process is stopped, usually via SIGSTOP or SIGTSTP. It can also be stopped by a debugger (ptrace). When you see that state, it usually is because you used Ctrl-Z to put a command on the background.

Linux进程状态解析 之 R、S、D、T、Z、X (主要有三个状态) - sdkdlwk的博客 - CSDN博客

Linux Process States - Stack Overflow - answered by zerodeux

S状态

大部分空闲时的进程都处于该状态。

D状态

linux - What is an uninterruptable process? - Stack Overflow - answered by CesarB

Uninterruptable processes are USUALLY waiting for I/O following a page fault.

Consider this:

  • The thread tries to access a page which is not in core (either an executable which is demand-loaded, a page of anonymous memory which has been swapped out, or a mmap()’d file which is demand loaded, which are much the same thing)
  • The kernel is now (trying to) load it in
  • The process can’t continue until the page is available.

The process/task cannot be interrupted in this state, because it can’t handle any signals; if it did, another page fault would happen and it would be back where it was.

When I say “process”, I really mean “task”, which under Linux (2.6) roughly translates to “thread” which may or may not have an individual “thread group” entry in /proc

In some cases, it may be waiting for a long time. A typical example of this would be where the executable or mmap’d file is on a network filesystem where the server has failed. If the I/O eventually succeeds, the task will continue. If it eventually fails, the task will generally get a SIGBUS or something.

D状态,为了保护进程数据与硬件状态一致,可看为是系统对进程和硬件设备的保护机制。正常情况下,D状态持续时间很短,一般可以忽略。如果出现大量D状态,需要关注是否io性能出现问题。

其他参考链接

本文完,作者yoko,尊重劳动人民成果,转载请注明原文出处: https://pengrl.com/p/21094/

0%