pidstat is a command-line tool from the sysstat package that reports resource usage per process and per thread on Linux, sampling CPU time, memory faults, disk I/O, context switches and stack usage at a fixed interval. In Linux monitoring, it fills the gap between system-wide counters such as vmstat or mpstat and interactive viewers such as top: it answers which task consumed the resource, in a plain, scriptable text format.
Because pidstat reads the same kernel accounting data that the kernel exposes under procfs, it adds almost no overhead and needs no tracing infrastructure. Administrators use it to attribute load, to compare threads of one service and to record repeatable time series during an incident or a benchmark.
How pidstat collects per-process statistics
pidstat works by reading counters from /proc twice and printing the difference. For every task it parses files such as /proc/[pid]/stat, /proc/[pid]/io and /proc/[pid]/status, stores the cumulative values, waits for the sampling interval, reads them again and divides the delta by the elapsed time. The result is a rate per second or a percentage of one CPU, not a lifetime total.
The basic syntax is pidstat [options] [interval [count]]. Without an interval, pidstat prints averages since boot or since process start, which are rarely useful for diagnosis. With pidstat 1 10, it prints ten one-second reports followed by an Average line per task, which is the form most practitioners rely on.
By default, pidstat shows only tasks that were active during the interval. Idle processes disappear from the output, which keeps reports short on busy servers but can surprise newcomers. The option -p ALL includes every task, and -p followed by a list of PIDs restricts the report to selected processes.
The following table maps the main report types to their switches and the kernel sources they read.
| Option | Report | Kernel source | Key columns |
|---|---|---|---|
| -u (default) | CPU utilization | /proc/[pid]/stat | %usr, %system, %guest, %wait, %CPU |
| -r | Page faults and memory | /proc/[pid]/stat, status | minflt/s, majflt/s, VSZ, RSS, %MEM |
| -d | Disk I/O | /proc/[pid]/io | kB_rd/s, kB_wr/s, kB_ccwr/s, iodelay |
| -w | Context switches | /proc/[pid]/status | cswch/s, nvcswch/s |
| -s | Stack usage | /proc/[pid]/status | StkSize, StkRef |
| -v | Kernel tables | /proc/[pid]/stat, fd | threads, fd-nr |
| -R | Scheduling policy | /proc/[pid]/stat | prio, policy |
Reading the pidstat output columns
Each pidstat column measures one precise counter, and several of them are easy to misread. The CPU report expresses usage as a percentage of a single CPU, so a multithreaded process on an eight-core host can legitimately show up to 800 percent. The option -I divides the value by the number of processors on SMP systems.
The table below explains the columns that matter most in daily diagnosis and what an abnormal value usually indicates.
| Column | Meaning | What a high value suggests |
|---|---|---|
| %usr | Time in user space | Computation in application code |
| %system | Time in kernel code | Heavy system calls, locking or networking |
| %wait | Runnable but waiting for a CPU | CPU saturation or cgroup throttling |
| majflt/s | Faults that required disk reads | Memory pressure or swapping |
| kB_ccwr/s | Writes canceled before flush | Temporary files deleted quickly |
| iodelay | Clock ticks blocked on block I/O | Slow storage affecting this task |
| nvcswch/s | Involuntary context switches | Competition for CPU time |
| cswch/s | Voluntary context switches | Frequent blocking on I/O or locks |
The %wait column deserves particular attention. It reflects scheduler run-queue delay, not I/O wait, and therefore reveals CPU contention that the %CPU figure hides. The iodelay field comes from delay accounting, which on recent kernels must be enabled with the delayacct boot parameter or the kernel.task_delayacct sysctl; otherwise it stays at zero.
Per-thread and per-command filtering
pidstat can descend from processes to individual threads, which is its main advantage over many other tools. The option -t prints a TGID line for each process followed by one TID line per thread, so an administrator can see that one worker thread of a database consumes most of the CPU while the others sleep.
Several options narrow the scope. -C filters by a command name pattern, -G by process name, and -T CHILD accumulates statistics of a process together with its terminated children, which suits build jobs and shell scripts that spawn short-lived helpers. The option -l prints the full command line, and -h puts every metric on a single line for machine parsing.
pidstat -t -p 1234 1shows every thread of process 1234 each second.pidstat -u -C nginx 5 12samples all nginx processes for one minute.pidstat -d -l 2lists disk activity with full command lines.pidstat -T CHILD -e make -j8measures a build including its children.
How pidstat compares with related Linux monitoring tools
pidstat belongs to a family of sampling tools that each answer a different question. It is not interactive, it does not keep history by itself and it does not trace individual events. Its strength is per-task attribution in reproducible text, which complements the system-wide view of other utilities.
| Tool | Scope | Output style | Best used for |
|---|---|---|---|
| pidstat | Per process and thread | Interval text reports | Attributing load to tasks |
| top and htop | Per process | Interactive screen | Quick live inspection |
| iotop | Per process I/O | Interactive screen | Spotting live disk writers |
| mpstat | Per CPU core | Interval text reports | Uneven core utilization |
| sar | System-wide | Stored history | Trends over days |
| strace and perf | Events and samples | Traces and profiles | Explaining why a task is slow |
A practical rule follows from this division. Use system-wide tools to detect a problem, pidstat to identify the responsible task, and tracing tools such as strace, perf or bpftrace to explain its behavior.
Limitations and common mistakes
pidstat is accurate within its design, but its sampling model imposes real limits. A process that starts and exits between two samples is never reported, so short-lived tasks require -T CHILD on a parent, the -e option or an event-based tool. Values are also rounded to clock ticks, which makes very small percentages noisy.
| Mistake | Consequence | Fix |
|---|---|---|
| Running without an interval | Lifetime averages hide spikes | Always pass an interval such as 1 or 5 |
| Reading %CPU as a host share | Overestimating load | Use -I or divide by core count |
| Confusing %wait with I/O wait | Wrong diagnosis | Treat it as CPU run-queue delay |
| Ignoring permissions | Missing I/O data for other users | Run as root for -d on foreign tasks |
| Expecting iodelay by default | Column stays at zero | Enable task delay accounting |
Another frequent misunderstanding concerns disk statistics. The kB_wr/s value counts data that the task caused to be written to storage, which can happen later through writeback, so page cache behavior can shift writes in time. Container users should also remember that pidstat sees host PIDs unless it runs inside the same PID namespace.
The short version
pidstat is a tool that tells you which program is using the computer, and how much. Other tools can say that the processor is busy or that the disk is working hard. pidstat names the specific program, or even the specific part of a program, that causes it.
Think of an electricity bill for a whole house compared with a meter on every appliance. The house bill shows that something uses too much power. pidstat is the meter on each appliance, read again every second so you can watch the numbers change.
Where it makes a difference
An operations engineer receives an alert that an API server with eight cores shows rising response times, although overall CPU usage sits at a moderate 55 percent. She runs pidstat -u -t -p 4120 1 30 against the Java application process and notices that one thread shows %CPU near 100 while also reporting a %wait of about 30 percent for the request workers.
A second run with pidstat -w -t -p 4120 1 reveals thousands of involuntary context switches per second among the worker threads. The busy thread turns out to be a garbage collection thread competing with request handlers inside a container limited to four CPUs. After the team raises the CPU quota and adjusts the collector settings, the %wait values fall below 5 percent and median latency returns to its normal level within the hour.