OnCallReadyStart learning

pidstat: Report statistics for Linux tasks

pidstat [ -d ] [ -H ] [ -h ] [ -I ] [ -l ] [ -R ] [ -r ] [ -s ] [ -t ] [ -U [ username ] ] [ -u ] [ -V ] [ -v ] [ -w ] [ -C comm ] [ -G process_name ] [ -p { pid[,...] | SELF | ALL } ] [ -T { TASK | CHILD | ALL } ] [ interval [ count ] ] [ -e program args ]

What it does

pidstat monitors individual tasks: CPU (-u, the default), memory and page faults (-r), disk I/O (-d), context switches (-w), threads (-t). Without -p it shows only tasks that were active in the interval.

Options you will use

-u
CPU: %usr %system %guest %wait %CPU and the CPU number. %wait = time runnable but waiting for a CPU (saturation).
-d
I/O: kB_rd/s kB_wr/s kB_ccwr/s iodelay. Needs root to see other users' tasks (it reads /proc/PID/io); iodelay is 0 unless kernel.task_delayacct=1.
-r
page faults and memory: minflt/s majflt/s VSZ RSS %MEM.
-w
context switches: cswch/s (voluntary, blocking) and nvcswch/s (involuntary, preempted).
-t
also each thread of the selected tasks (TGID and TID).
-p { pid[,...] | SELF | ALL }
only these tasks (ALL = every task, active or not).
-C comm
only tasks whose command name contains the string (a regex).
-l
the full command line with its arguments.
-h
everything on one line, no average (for scripts).
-U [ username ]
show the user name, optionally only that user's tasks.
-H
timestamps in seconds since the epoch.
-V
print version number then exit.
interval [count]
report every INTERVAL seconds, COUNT times (no count = until Ctrl+C). The first report covers the time since boot (iostat: unless -y).

Examples

$ pidstat 1

busy processes, every second

$ sudo pidstat -d 1

who reads and writes the disks

$ pidstat -t -p 1210 1

per thread of one process

$ pidstat -w 1

context switches per process

Gotchas

Taught in

On the blog

Try pidstat in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.