Linux Command Guide: pidstat

pidstat reports per-process statistics over time. It is part of the sysstat package and is ideal for tracking CPU, memory, I/O, and thread-level activity.

What pidstat is good for

Install

Install (sysstat package)
# Debian/Ubuntu
sudo apt install sysstat

# RHEL/CentOS/Fedora
sudo dnf install sysstat

# Arch
sudo pacman -S sysstat

10 Practical Examples

1) Basic CPU usage (1-second interval)
pidstat 1
2) CPU stats for a specific PID
pidstat -p 1234 1
3) Monitor multiple PIDs
pidstat -p 1234,5678 2
4) Show memory usage
pidstat -r 2
5) Show I/O statistics
pidstat -d 2
6) Show context switches
pidstat -w 2
7) Show threads instead of processes
pidstat -t 2
8) Show only specific user processes
pidstat -u -U username 2
9) Run for fixed samples
pidstat 2 30
10) Save output to file
pidstat 1 60 > pidstat.log