Pidstat Overview
Pidstat is a command for the Sysstat tool that monitors the CPU, memory, thread, device IO, and other system resources of all or specified processes. Pidstat displays statistics from the start of the system startup at the first run, and then runs Pidstat displays statistics from the last time the command was run. Users can obtain the required statistics by specifying the number and time of the statistics.
Pidstat Installation
Pidstat is part of the Sysstat software suite, and Sysstat contains many tools for monitoring the state of Linux systems, which can be obtained from most Linux distribution software sources.
- The following command can be used in the Debian/ubuntu system to install:
Apt-get Install Sysstat
- The following command is used in the Centos/fedora/rhel version of Linux:
Yum Install Sysstat
Pidstat Example
Usage of Pidstat:
pidstat [ 选项 ] [ <时间间隔> ] [ <次数> ]
Such as:
Common parameters:
- -u: Default parameter that shows CPU usage statistics for each process
- -R: Show memory usage statistics for each process
- -D: Show IO usage for each process
- -P: Specify the process number
- -W: Shows context switching for each process
- -T: Displays additional information outside the statistics of the selected task's thread
- -T {TASK | Child | All}
This option specifies the Pidstat monitor. The task representation reports the independent Task,child keyword representing all thread statistics under the reporting process. All indicates that all threads under separate task and task are reported.
Note: The global statistics for task and child threads are independent of the PIDSTAT option. These statistics do not correspond to the current statistical interval, and these statistics are collected only when the child thread is killed or completed.
- -V: Version number
- -H: All activities are displayed on a single line so that other programs can be easily parsed.
- -I: In an SMP environment, indicates the CPU usage/number of cores of a task
- -L: Show command name and all parameters
Example one: View CPU usage for all processes (-u-p all)
pidstatpidstat -u -p ALL
Pidstat and Pidstat-u-P all are equivalent.
Pidstat shows the CPU utilization of all processes by default.
Detailed description
- PID: Process ID
- %USR: Percentage of CPU consumed by the process in user space
- %system: Percentage of CPU consumed by the process in kernel space
- %guest: Percentage of CPU consumed by the process in the virtual machine
- %cpu: Percentage of CPU consumed by process
- CPU: CPU number of the processing process
- Command: Commands that correspond to the current process
Example two: CPU usage statistics (-u)
pidstat -u
With the-u option, Pidstat displays the CPU usage statistics for each active process, performing "Pidstat-u" the same as performing "Pidstat" alone.
Example three: Memory usage statistics (-R)
pidstat -r
Using the-r option, Pidstat displays the memory usage statistics for each active process:
- PID: Process Identifier
- MINFLT/S: Minor error occurred per second for task, no need to load page from disk
- MAJFLT/S: The primary error that occurs per second for a task that requires the page to be loaded from disk
- VSZ: Virtual address size, use of virtual memory kb
- RSS: Resident collection size, non-swap zone five memory usage kb
- Command:task command name
Example four: Show IO usage for each process (-D)
pidstat -d
The report IO statistics shows the following information:
- PID: Process ID
- KB_RD/S: KB read per second from disk
- KB_WR/S: Write disk KB per second
- KB_CCWR/S: The KB of the write disk to which the task was canceled. Occurs when a task truncates a dirty pagecache.
- Command:task's command name
Example five: Show context switching for each process (-W)
pidstat -w -p 2831
- PID: Process ID
- CSWCH/S: Number of active task context switches per second
- NVCSWCH/S: Number of passive task context switches per second
- Command: Commands name
Example SIX: Display additional information outside the statistics of the selected task's thread (-t)
pidstat -t -p 2831
- Tgid: The representation of the main thread
- TID: Thread ID
- %USR: Percentage of CPU consumed by the process in user space
- %system: Percentage of CPU consumed by the process in kernel space
- %guest: Percentage of CPU consumed by the process in the virtual machine
- %cpu: Percentage of CPU consumed by process
- CPU: CPU number of the processing process
- Command: Commands that correspond to the current process
Example VII: PIDSTAT-T
pidstat -T TASKpidstat -T CHILDpidstat -T ALL
A task represents a separate task that is reported.
The child keyword represents all thread statistics under the reporting process.
All indicates that all threads under separate task and task are reported.
Note: The global statistics for task and child threads are independent of the PIDSTAT option. These statistics do not correspond to the current statistical interval, and these statistics are collected only when the child thread is killed or completed.
- PID: Process ID
- Usr-ms: The number of milliseconds that tasks and child threads use at the user level.
- System-ms: The number of milliseconds that tasks and child threads use at the system level.
- Guest-ms: The number of milliseconds that the task and child threads use in the virtual machine (running a Vsan processor).
- Command: Commands name
Linux Pidstat Command detailed