pidstat

Monitor the system resource usage of processes

illustrate

pidstat is a command of the sysstat tool, which is used to monitor the usage of system resources such as CPU, memory, threads, and device IO for all or specified processes. When pidstat is run for the first time, various statistical information will be displayed since the system startup. Running pidstat thereafter will display statistical information since the last time the command was run. Users can obtain the required statistical information by specifying the number and time of statistics.

grammar

pidstat [options] [<time interval>] [<number of times>]

Options

-u: Default parameter, displays cpu usage statistics of each process -r: Display memory usage statistics of each process -d: Display the IO usage of each process -w: Display the context switching status of each process -t: Displays statistics about threads -p: Specify the process number

Example

View the CPU usage of all processes

# pidstat -u -p ALL
11:04:06 AM UID PID %usr %system %guest %CPU CPU Command
11:04:06 AM 0 1 0.03 0.05 0.00 0.08 20 systemd
11:04:06 AM 0 2 0.00 0.00 0.00 0.00 28 kthreadd
11:04:06 AM 0 3 0.00 0.00 0.00 0.00 0 rcu_gp
11:04:06 AM 0 4 0.00 0.00 0.00 0.00 0 rcu_par_gp
11:04:06 AM 0 6 0.00 0.00 0.00 0.00 0 kworker/0:0H-kblockd
11:04:06 AM 0 9 0.00 0.00 0.00 0.00 38 mm_percpu_wq
11:04:06 AM 0 10 0.00 0.01 0.00 0.01 0 ksoftirqd/0
11:04:06 AM 0 11 0.00 0.23 0.00 0.23 15 rcu_sched
11:04:06 AM 0 12 0.00 0.00 0.00 0.00 0 migration/0
11:04:06 AM 0 14 0.00 0.00 0.00 0.00 0 cpuhp/0
11:04:06 AM 0 15 0.00 0.00 0.00 0.00 1 cpuhp/1
...

Header field description

View the memory usage of all processes

# pidstat -r
11:10:35 AM UID PID minflt/s majflt/s VSZ RSS %MEM Command
11:10:35 AM 0 1 7.24 0.05 191312 4208 0.01 systemd
11:10:35 AM 0 1407 2.02 0.09 39316 9016 0.03 systemd-journal
11:10:35 AM 0 1442 0.03 0.00 190380 1080 0.00 lvmetad
11:10:35 AM 0 1457 0.46 0.00 46252 1560 0.00 systemd-udevd
11:10:35 AM 0 2429 0.11 0.00 163620 9472 0.03 sshd
11:10:35 AM 992 2446 0.02 0.00 8588 996 0.00 lsmd
11:10:35 AM 0 2447 0.05 0.00 90572 1468 0.00 rngd
11:10:35 AM 0 2448 0.15 0.02 451272 3520 0.01 udisksd
11:10:35 AM 0 2449 0.18 0.02 396488 1948 0.01 accounts-daemon
11:10:35 AM 0 2454 0.02 0.02 201336 1464 0.00 gssproxy
...

Header field description

View the IO usage of all processes

# pidstat -d
11:12:30 AM UID PID kB_rd/s kB_wr/s kB_ccwr/s Command
11:12:30 AM 0 1 250.05 11.57 2.13 systemd
11:12:30 AM 0 224 1.21 0.00 0.00 khugepaged
11:12:30 AM 0 290 0.03 0.00 0.00 kswapd0
11:12:30 AM 0 291 0.02 0.00 0.00 kswapd1
11:12:30 AM 0 1312 1.03 0.00 0.00 xfsaild/dm-0
11:12:30 AM 0 1407 1.31 0.00 0.00 systemd-journal
11:12:30 AM 0 1442 0.01 0.00 0.00 lvmetad
11:12:30 AM 0 1457 1.77 0.00 0.00 systemd-udevd
11:12:30 AM 992 2446 0.79 0.00 0.00 lsmd
11:12:30 AM 0 2447 0.07 0.00 0.00 rngd
11:12:30 AM 0 2448 0.46 0.00 0.00 udisksd
...

Header field description -PID: process id

Check the context switching of the process

# pidstat -w
11:15:52 AM UID PID cswch/s nvcswch/s Command
11:15:52 AM 0 1 3.15 0.03 systemd
11:15:52 AM 0 2 0.13 0.00 kthreadd
11:15:52 AM 0 3 0.00 0.00 rcu_gp
11:15:52 AM 0 4 0.00 0.00 rcu_par_gp
11:15:52 AM 0 6 0.00 0.00 kworker/0:0H-kblockd
11:15:52 AM 0 9 0.00 0.00 mm_percpu_wq
11:15:52 AM 0 10 1.99 0.00 ksoftirqd/0
...

Header field meaning