Pidstat-monitors and counts Linux Process Data
The pidstat command is used to monitor independent tasks (processes) managed by the Linux kernel ). It outputs information about each task managed by the kernel. The pidstat command can also be used to monitor sub-processes of a specific process. The interval parameter is used to specify the interval between each report. The value 0 (or no parameter) indicates that the statistical time of the process is calculated from the start of the system.
How to install pidstat
Pidstat is part of the sysstat software suite. sysstat contains many tools that monitor the status of linux systems and can be obtained from most software sources in linux releases.
In Debian/Ubuntu, you can use the following command to install
- # Apt-get install sysstat
In CentOS/Fedora/RHEL linux, run the following command:
- # Yum install sysstat
Use pidstat
Using pidstat without any parameters is equivalent to adding the-p parameter, but only active tasks are displayed.
- # Pidstat
You can see the following content in the result:
- PID-process ID of the monitored task
- % Usr-the cpu usage of the task when the application is executed at the user layer, regardless of the nice priority. Note that the cpu time calculated by this field does not include the time spent in the virtual processor.
- % System-cpu usage of this task at the system layer.
- % Guest-cpu usage (running on the virtual processor) of the task on the virtual machine ).
- % CPU-total cpu usage of the task. In the SMP environment (multi-processor), if you enter the-I parameter in the command line, the cpu usage will be divided by the number of your CPUs.
- CPU-the number of the processor that is running the task.
- Command-Command name of the task.
I/O statistics
Use the-d parameter to obtain the I/O statistics. For example:
- # Pidstat-d-p 8472
IO output will display some internal entries:
- KB_rd/s-read speed of the task from the hard disk (kb)
- KB_wr/s-write speed (kb) of the task to the hard disk)
- KB_ccwr/s-speed at which the task is written to the disk canceled (kb)
Page failure and memory usage
Use-r to mark the data that you can get memory usage.
Important entries:
- Minflt/s-the number of small errors that occur every second when loading data from the memory. These do not require loading the memory page from the disk.
- Majflt/s-the number of large errors that occur per second when loading data from the memory. These requests are loaded into the memory page from the disk.
- VSZ-virtual capacity: virtual memory usage of the entire process (kb)
- RSS-long-term memory usage: The amount of physical memory that cannot be exchanged for tasks (kb)
Example
1. You can monitor memory usage by using the following command
- # Pidstat-r 2 5
This will give you 5 statistical results about page faults at an interval of 2 seconds. This will make it easier to locate the problematic process.
2. display the sub-processes of all mysql servers
- # Pidstat-t child-C mysql
3. Integrate all the statistical data into a single report that is easy to read:
- # Pidstat-urd-h
This article permanently updates the link address: