The pidstat
command is a useful tool for monitoring individual process statistics in real-time. It provides detailed information about CPU usage, memory consumption, and other performance metrics for running processes, making it invaluable for system administrators and developers who need to optimize performance.
The basic syntax of the pidstat
command is as follows:
pidstat [options] [arguments]
-h
: Display the output in a human-readable format.-r
: Report memory usage statistics.-u
: Report CPU usage statistics.-p <pid>
: Specify the process ID to monitor.-t
: Display statistics for threads.Here are some practical examples of how to use the pidstat
command:
pidstat -u 1
This command will display CPU usage statistics for all processes every second.
pidstat -r -p 1234 1
Replace 1234
with the actual process ID. This will show memory usage statistics for the specified process every second.
pidstat -u -r 1
This command will provide both CPU and memory usage statistics for all processes every second.
pidstat -t -p 5678 1
Replace 5678
with the desired process ID. This will display thread-level statistics for the specified process every second.
-h
option to make the output more readable, especially when dealing with large numbers.-u -r
together.pidstat [options] > output.txt
.