回到手册索引

命令用途

pidstat 是一个用于统计进程资源使用情况的 Linux 命令。它可以显示特定进程的 CPU、内存、I/O 等资源使用情况,适用于分析系统性能问题,监控进程行为等。

常用用法示例

  1. 显示所有进程的 CPU 使用情况

    1
    2
    3
    4
    5
    6
    pidstat
    Linux 4.15.0-96-generic (hostname) 02/26/2025 _x86_64_ (2 CPU)
    12:00:00 UID PID %usr %sys %guest %wait %idle CPU
    12:00:01 1000 2384 0.10 0.02 0.00 0.00 99.88 0
    12:00:02 1000 2385 0.12 0.03 0.00 0.00 99.85 1
    ...

    该命令显示了每个进程在各个 CPU 核心上的 CPU 使用情况。

  2. 显示每个进程的内存使用情况

    1
    2
    3
    4
    5
    pidstat -r
    12:00:00 UID PID minflt/s majflt/s VSZ RSS
    12:00:01 1000 2384 0.05 0.00 12345 1234
    12:00:02 1000 2385 0.04 0.01 12567 5678
    ...

    显示了每个进程的内存页面缺页次数、虚拟内存大小(VSZ)、常驻内存集大小(RSS)等信息。

  3. 显示某个特定进程的 CPU 使用情况

    1
    2
    3
    4
    pidstat -p 1234
    12:00:00 UID PID %usr %sys %guest %wait %idle CPU
    12:00:01 1000 1234 0.10 0.05 0.00 0.00 99.85 1
    ...

    通过 -p 选项,可以查看 PID 为 1234 的进程的 CPU 使用情况。

  4. 按照进程显示每秒的 CPU 使用情况

    1
    2
    3
    4
    5
    pidstat -u 1
    12:00:00 UID PID %usr %sys %guest %wait %idle CPU
    12:00:01 1000 2384 0.15 0.02 0.00 0.00 99.83 0
    12:00:02 1000 2385 0.10 0.01 0.00 0.00 99.89 1
    ...

    此命令每秒输出一次 CPU 使用情况,适用于实时监控。

  5. 显示指定时间间隔内每个进程的 CPU 使用情况

    1
    2
    3
    4
    5
    pidstat -u 2 5
    12:00:00 UID PID %usr %sys %guest %wait %idle CPU
    12:00:02 1000 2384 0.10 0.02 0.00 0.00 99.88 0
    12:00:04 1000 2385 0.12 0.03 0.00 0.00 99.85 1
    ...

    此命令会每 2 秒输出一次,共输出 5 次统计数据。

  6. 显示进程的 I/O 使用情况

    1
    2
    3
    4
    5
    pidstat -d
    12:00:00 UID PID kB_rd/s kB_wr/s kB_ccwr/s
    12:00:01 1000 2384 0.12 0.34 0.01
    12:00:02 1000 2385 0.15 0.50 0.02
    ...

    通过 -d 选项,查看每个进程的 I/O 读写情况。

  7. 显示所有进程的上下文切换情况

    1
    2
    3
    4
    5
    pidstat -w
    12:00:00 UID PID cswch/s nvcswch/s
    12:00:01 1000 2384 0.01 0.02
    12:00:02 1000 2385 0.02 0.03
    ...

    该命令显示了进程的上下文切换(cswch)及其数量(nvcswch)。

  8. 显示进程的线程使用情况

    1
    2
    3
    4
    5
    pidstat -t
    12:00:00 UID PID TGID %usr %sys %guest %wait %idle CPU
    12:00:01 1000 2384 2384 0.10 0.02 0.00 0.00 99.88 0
    12:00:02 1000 2385 2385 0.12 0.03 0.00 0.00 99.85 1
    ...

    通过 -t 选项,显示每个进程的线程相关的 CPU 使用情况。

  9. 显示内存使用率

    1
    2
    3
    4
    5
    pidstat -r 1
    12:00:00 UID PID minflt/s majflt/s VSZ RSS
    12:00:01 1000 2384 0.03 0.01 1234 234
    12:00:02 1000 2385 0.05 0.01 1256 456
    ...

    此命令每秒输出一次每个进程的内存使用情况。

  10. 显示进程的 CPU 和内存使用情况

    1
    2
    3
    4
    5
    pidstat -u -r
    12:00:00 UID PID %usr %sys %guest %wait %idle CPU VSZ RSS
    12:00:01 1000 2384 0.12 0.03 0.00 0.00 99.85 12345 1234
    12:00:02 1000 2385 0.10 0.02 0.00 0.00 99.88 12567 5678
    ...

    使用 -u 和 -r 选项同时显示 CPU 和内存使用情况。

  11. 显示特定时间间隔内所有进程的 I/O 使用情况

    1
    2
    3
    4
    5
    pidstat -d 2 5
    12:00:00 UID PID kB_rd/s kB_wr/s kB_ccwr/s
    12:00:02 1000 2384 0.12 0.34 0.01
    12:00:04 1000 2385 0.15 0.50 0.02
    ...

    每 2 秒输出一次,共输出 5 次 I/O 使用情况。

  12. 显示进程的所有资源使用情况

    1
    2
    3
    4
    5
    pidstat -d -u -r -w
    12:00:00 UID PID %usr %sys %guest %wait %idle CPU VSZ RSS kB_rd/s kB_wr/s kB_ccwr/s cswch/s nvcswch/s
    12:00:01 1000 2384 0.10 0.02 0.00 0.00 99.88 12345 1234 0.12 0.34 0.01 0.01 0.02
    12:00:02 1000 2385 0.12 0.03 0.00 0.00 99.85 12567 5678 0.15 0.50 0.02 0.02 0.03
    ...

    该命令结合了多种选项,显示进程的 CPU、内存、I/O 和上下文切换等多个资源的使用情况。

常用参数选项

  • -u, –cpu
    显示每个进程的 CPU 使用情况。
  • -r, –memory
    显示每个进程的内存使用情况。
  • -d, –io
    显示每个进程的 I/O 使用情况。
  • -w, –context
    显示每个进程的上下文切换情况。
  • -p, –pid
    指定要监控的进程 ID(PID)。
  • -t, –threads
    显示进程的线程使用情况。
  • -h, –help
    显示帮助信息。
  • -V, –version
    显示 pidstat 版本信息。
  • -s, –summarize
    按汇总显示统计信息,合并多个进程的资源使用情况。
  • -I, –interval
    指定时间间隔,单位为秒,用于每隔一定时间刷新输出。
  • -l, –long
    以更详细的格式显示信息,显示更多统计字段。
  • -c, –cpu-summary
    显示每个 CPU 核心的使用情况。

原厂文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
NAME
pidstat - Report statistics for Linux tasks.


SYNOPSIS
pidstat [ -d ] [ -H ] [ -h ] [ -I ] [ -l ] [ -R ] [ -r ] [ -s ] [ -t ] [
-U [ username ] ] [ -u ] [ -V ] [ -v ] [ -w ] [ -C comm ] [ -G
process_name ] [ --dec={ 0 | 1 | 2 } ] [ --human ] [ -o JSON ] [ -p {
pid[,...] | SELF | ALL } ] [ -T { TASK | CHILD | ALL } ] [ interval [
count ] ] [ -e program args ]


DESCRIPTION
The pidstat command is used for monitoring individual tasks currently
being managed by the Linux kernel. It writes to standard output
activities for every task selected with option -p or for every task
managed by the Linux kernel if option -p ALL has been used. Not selecting
any tasks is equivalent to specifying -p ALL but only active tasks (tasks
with non-zero statistics values) will appear in the report.

The pidstat command can also be used for monitoring the child processes
of selected tasks. Read about option -T below.

The interval parameter specifies the amount of time in seconds between
each report. A value of 0 (or no parameters at all) indicates that tasks
statistics are to be reported for the time since system startup (boot).
The count parameter can be specified in conjunction with the interval
parameter if this one is not set to zero. The value of count determines
the number of reports generated at interval seconds apart. If the
interval parameter is specified without the count parameter, the pidstat
command generates reports continuously.

You can select information about specific task activities using flags.
Not specifying any flags selects only CPU activity.


OPTIONS
-C comm
Display only tasks whose command name includes the string comm.
This string can be a regular expression.

-d Report I/O statistics (kernels 2.6.20 and later only). The
following values may be displayed:

UID The real user identification number of the task being
monitored.

USER The name of the real user owning the task being monitored.

PID The identification number of the task being monitored.

kB_rd/s
Number of kibibytes the task has caused to be read from
disk per second.

kB_wr/s
Number of kibibytes the task has caused, or shall cause to
be written to disk per second.

kB_ccwr/s
Number of kibibytes whose writing to disk has been
cancelled by the task. This may occur when the task
truncates some dirty pagecache. In this case, some IO which
another task has been accounted for will not be happening.

iodelay
Block I/O delay of the task being monitored, measured in
clock ticks. This metric includes the delays spent waiting
for sync block I/O completion and for swapin block I/O
completion.

Command
The command name of the task.

--dec={ 0 | 1 | 2 }
Specify the number of decimal places to use (0 to 2, default value
is 2).

-e program args
Execute program with given arguments args and monitor it with
pidstat. pidstat stops when program terminates. A non-zero value
must be specified for the interval parameter.

-G process_name
Display only processes whose command name includes the string
process_name. This string can be a regular expression. If option
-t is used together with option -G then the threads belonging to
that process are also displayed (even if their command name
doesn't include the string process_name).

-H Display timestamp in seconds since the epoch.

-h Display all activities horizontally on a single line, with no
average statistics at the end of the report. This is intended to
make it easier to be parsed by other programs.

--human
Print sizes in human readable format (e.g. 1.0k, 1.2M, etc.) The
units displayed with this option supersede any other default units
(e.g. kibibytes, sectors...) associated with the metrics.

-I In an SMP environment, indicate that tasks CPU usage (as displayed
by option -u) should be divided by the total number of processors.

-l Display the process command name and all its arguments.

-o JSON
Display the statistics in JSON (JavaScript Object Notation)
format. JSON output field order is undefined, and new fields may
be added in the future.

-p { pid[,...] | SELF | ALL }
Select tasks (processes) for which statistics are to be reported.
pid is the process identification number. The SELF keyword
indicates that statistics are to be reported for the pidstat
process itself, whereas the ALL keyword indicates that statistics
are to be reported for all the tasks managed by the system.

-R Report realtime priority and scheduling policy information. The
following values may be displayed:

UID The real user identification number of the task being
monitored.

USER The name of the real user owning the task being monitored.

PID The identification number of the task being monitored.

prio The realtime priority of the task being monitored.

policy The scheduling policy of the task being monitored.

Command
The command name of the task.

-r Report page faults and memory utilization.

When reporting statistics for individual tasks, the following
values may be displayed:

UID The real user identification number of the task being
monitored.

USER The name of the real user owning the task being monitored.

PID The identification number of the task being monitored.

minflt/s
Total number of minor faults the task has made per second,
those which have not required loading a memory page from
disk.

majflt/s
Total number of major faults the task has made per second,
those which have required loading a memory page from disk.

VSZ Virtual Size: The virtual memory usage of entire task in
kibibytes.

RSS Resident Set Size: The non-swapped physical memory used by
the task in kibibytes.

%MEM The tasks's currently used share of available physical
memory.

Command
The command name of the task.

When reporting global statistics for tasks and all their children,
the following values may be displayed:

UID The real user identification number of the task which is
being monitored together with its children.

USER The name of the real user owning the task which is being
monitored together with its children.

PID The identification number of the task which is being
monitored together with its children.

minflt-nr
Total number of minor faults made by the task and all its
children, and collected during the interval of time.

majflt-nr
Total number of major faults made by the task and all its
children, and collected during the interval of time.

Command
The command name of the task which is being monitored
together with its children.

-s Report stack utilization. The following values may be displayed:

UID The real user identification number of the task being
monitored.

USER The name of the real user owning the task being monitored.

PID The identification number of the task being monitored.

StkSize
The amount of memory in kibibytes reserved for the task as
stack, but not necessarily used.

StkRef The amount of memory in kibibytes used as stack, referenced
by the task.

Command
The command name of the task.

-T { TASK | CHILD | ALL }
This option specifies what has to be monitored by the pidstat
command. The TASK keyword indicates that statistics are to be
reported for individual tasks (this is the default option) whereas
the CHILD keyword indicates that statistics are to be globally
reported for the selected tasks and all their children. The ALL
keyword indicates that statistics are to be reported for
individual tasks and globally for the selected tasks and their
children.

Note: Global statistics for tasks and all their children are not
available for all options of pidstat. Also these statistics are
not necessarily relevant to current time interval: The statistics
of a child process are collected only when it finishes or it is
killed.

-t Also display statistics for threads associated with selected
tasks.

This option adds the following values to the reports:

TGID The identification number of the thread group leader.

TID The identification number of the thread being monitored.

-U [ username ]
Display the real user name of the tasks being monitored instead of
the UID. If username is specified, then only tasks belonging to
the specified user are displayed.

-u Report CPU utilization.

When reporting statistics for individual tasks, the following
values may be displayed:

UID The real user identification number of the task being
monitored.

USER The name of the real user owning the task being monitored.

PID The identification number of the task being monitored.

%usr Percentage of CPU used by the task while executing at the
user level (application), with or without nice priority.
Note that this field does NOT include time spent running a
virtual processor.

%system
Percentage of CPU used by the task while executing at the
system level (kernel).

%guest Percentage of CPU spent by the task in virtual machine
(running a virtual processor).

%wait Percentage of CPU spent by the task while waiting to run.

%CPU Total percentage of CPU time used by the task. In an SMP
environment, the task's CPU usage will be divided by the
total number of CPU's if option -I has been entered on the
command line.

CPU Processor number to which the task is attached.

Command
The command name of the task.

When reporting global statistics for tasks and all their children,
the following values may be displayed:

UID The real user identification number of the task which is
being monitored together with its children.

USER The name of the real user owning the task which is being
monitored together with its children.

PID The identification number of the task which is being
monitored together with its children.

usr-ms Total number of milliseconds spent by the task and all its
children while executing at the user level (application),
with or without nice priority, and collected during the
interval of time. Note that this field does NOT include
time spent running a virtual processor.

system-ms
Total number of milliseconds spent by the task and all its
children while executing at the system level (kernel), and
collected during the interval of time.

guest-ms
Total number of milliseconds spent by the task and all its
children in virtual machine (running a virtual processor).

Command
The command name of the task which is being monitored
together with its children.

-V Print version number then exit.

-v Report values of some kernel tables. The following values may be
displayed:

UID The real user identification number of the task being
monitored.

USER The name of the real user owning the task being monitored.

PID The identification number of the task being monitored.

threads
Number of threads associated with current task.

fd-nr Number of file descriptors associated with current task.

Command
The command name of the task.

-w Report task switching activity (kernels 2.6.23 and later only).
The following values may be displayed:

UID The real user identification number of the task being
monitored.

USER The name of the real user owning the task being monitored.

PID The identification number of the task being monitored.

cswch/s
Total number of voluntary context switches the task made
per second. A voluntary context switch occurs when a task
blocks because it requires a resource that is unavailable.

nvcswch/s
Total number of non voluntary context switches the task
made per second. An involuntary context switch takes place
when a task executes for the duration of its time slice and
then is forced to relinquish the processor.

Command
The command name of the task.


ENVIRONMENT
The pidstat command takes into account the following environment
variables:

S_COLORS
By default statistics are displayed in color when the output is
connected to a terminal. Use this variable to change the
settings. Possible values for this variable are never, always or
auto (the latter is equivalent to the default settings).
Please note that the color (being red, yellow, or some other
color) used to display a value is not indicative of any kind of
issue simply because of the color. It only indicates different
ranges of values.

S_COLORS_SGR
Specify the colors and other attributes used to display statistics
on the terminal. Its value is a colon-separated list of
capabilities that defaults to
I=32;22:N=34;1:W=35;1:X=31;1:Z=34;22. Supported capabilities are:

I= SGR (Select Graphic Rendition) substring for item values
like PID, UID or CPU number.

N= SGR substring for non-zero statistics values and for tasks
names.

W= (or M=)
SGR substring for percentage values in the range from 75%
to 90% (or in the range 10% to 25% depending on the
metric's meaning).

X= (or H=)
SGR substring for percentage values greater than or equal
to 90% (or lower than or equal to 10% depending on the
metric's meaning).

Z= SGR substring for zero values and for threads names.

S_TIME_FORMAT
If this variable exists and its value is ISO then the current
locale will be ignored when printing the date in the report
header. The pidstat command will use the ISO 8601 format (YYYY-MM-
DD) instead. The timestamp will also be compliant with ISO 8601
format.


EXAMPLES
pidstat 2 5
Display five reports of CPU statistics for every active task in
the system at two second intervals.

pidstat -r -p 1643 2 5
Display five reports of page faults and memory statistics for PID
1643 at two second intervals.

pidstat -C "fox|bird" -r -p ALL
Display global page faults and memory statistics for all the
processes whose command name includes the string "fox" or "bird".

pidstat -T CHILD -r 2 5
Display five reports of page faults statistics at two second
intervals for the child processes of all tasks in the system. Only
child processes with non-zero statistics values are displayed.


BUGS
/proc filesystem must be mounted for the pidstat command to work.

Although pidstat displays units corresponding to kilobytes (kB),
megabytes (MB)..., it actually uses kibibytes (kiB), mebibytes (MiB)...
A kibibyte is equal to 1024 bytes, and a mebibyte is equal to 1024
kibibytes.


FILES
/proc contains various files with system statistics.


AUTHOR
Sebastien Godard (sysstat <at> orange.fr)


SEE ALSO
sar(1), top(1), ps(1), mpstat(1), iostat(1), vmstat(8)

https://github.com/sysstat/sysstat
https://sysstat.github.io/