PIDSTAT(1)

๐Ÿ“ฆ
version 12.8.0 ยท 5 versions
, in alpine 3.24, arch rolling, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– pidstat(1) ๐Ÿ’–

Linux User's Manual โœจ pidstat is the manual name, bestie ๐Ÿฆ‹

๐ŸŒธ NAME ๐ŸŒธ

pidstat - Report statistics for Linux tasks. ๐Ÿ“Š

๐ŸŽ€ SYNOPSIS ๐ŸŽ€

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

๐ŸŒท DESCRIPTION ๐ŸŒท

okay so pidstat is the command you use to keep an eye on the individual tasks the Linux kernel is currently juggling ๐Ÿ‘€. It spits its stats out to standard output for every task you pick with -p, or for literally every task on the system if you use -p ALL ๐Ÿ’…. If you don't select any tasks at all, that's the same as -p ALL, but only the active tasks (the ones with non-zero stats) show up in the report. no cap, very helpful ๐Ÿซถ

It can also keep tabs on the child processes of whatever tasks you've selected. Check out -T below for the tea on that one โ˜•.

The interval parameter is how many seconds go by between each report โฐ. If you give it a value of 0 (or you don't give any parameters at all), the stats are reported for the time since the system booted ๐Ÿฅน. The count parameter only works alongside interval, and only if interval isn't zero. It decides how many reports get generated, spaced interval seconds apart โœจ. If you give interval but skip count, pidstat just keeps reporting nonstop, iykyk ๐Ÿ™ˆ.

You can pick out specific task activities with flags ๐Ÿšฉ. And if you don't use any flags? You only get CPU activity, periodt ๐Ÿ’œ.

๐Ÿ’… OPTIONS ๐Ÿ’…

  • -C comm โ€” Only show tasks whose command name includes the string comm. Yes, this string can be a regular expression, we love a power move ๐Ÿ”ฅ.
  • -d โ€” Report I/O statistics. This only works on kernels 2.6.20 and later, so no old-school vibes ๐Ÿ•ฐ๏ธ. Here's what you'll see:
    • UID โ€” The real user ID number of the task being monitored ๐Ÿ†”.
    • USER โ€” The name of the real user who owns the task being monitored ๐Ÿง‘.
    • PID โ€” The ID number of the task being monitored ๐Ÿ”ข.
    • kB_rd/s โ€” How many kibibytes the task has made get read from disk per second ๐Ÿ“–.
    • kB_wr/s โ€” How many kibibytes the task has caused, or is about to cause, to get written to disk per second โœ๏ธ.
    • kB_ccwr/s โ€” How many kibibytes that were headed for disk got cancelled by the task. This can happen when the task truncates some dirty pagecache. In that case, some I/O that another task got credited for won't actually happen ๐Ÿ’€.
    • iodelay โ€” The block I/O delay of the task being monitored, measured in clock ticks โฑ๏ธ. This includes the delays spent waiting for sync block I/O to finish, and for swapin block I/O to finish too ๐Ÿข.
    • Command โ€” The command name of the task ๐ŸŽฌ.
  • --dec={ 0 | 1 | 2 } โ€” Pick how many decimal places you want, anywhere from 0 to 2. The default is 2 ๐Ÿ’ฏ.
  • -e program args โ€” Run program with the given args and monitor it with pidstat. pidstat stops once program finishes ๐Ÿ. You have to give the interval parameter a non-zero value for this one ๐Ÿซก.
  • -G process_name โ€” Only show processes whose command name includes the string process_name. Regular expressions are welcome here too ๐Ÿ˜Œ. If you use -t together with -G, the threads that belong to that process get shown as well, even if their command name doesn't include process_name ๐Ÿงต.
  • -H โ€” Show the timestamp in seconds since the epoch ๐Ÿ•ฐ๏ธ.
  • -h โ€” Show all activities horizontally on one single line, and skip the average statistics at the end of the report ๐Ÿ“. This is made so other programs can parse it more easily ๐Ÿค–.
  • --human โ€” Print sizes in a human readable format, like 1.0k or 1.2M ๐Ÿง. The units shown with this option replace any other default units attached to the metrics, like kibibytes or sectors ๐Ÿช„.
  • -I โ€” On an SMP system, this tells pidstat to divide the tasks' CPU usage (the stuff -u shows) by the total number of processors ๐Ÿงฎ.
  • -l โ€” Show the process command name and all of its arguments ๐Ÿ“œ.
  • -o JSON โ€” Show the stats in JSON (JavaScript Object Notation) format ๐Ÿงพ. The field order in JSON output is undefined, and new fields might get added in the future, so don't lock your code to one exact order ๐Ÿ™ƒ.
  • -p { pid[,...] | SELF | ALL } โ€” Pick the tasks (processes) you want stats for ๐ŸŽฏ. pid is the process ID number. The SELF keyword means "report on the pidstat process itself" ๐Ÿชž, while the ALL keyword means "report on every single task the system manages" ๐ŸŒ.
  • -R โ€” Report realtime priority and scheduling policy info ๐Ÿšฆ. Here's the lineup:
    • UID โ€” The real user ID number of the task being monitored ๐Ÿ†”.
    • USER โ€” The name of the real user who owns the task being monitored ๐Ÿง‘.
    • PID โ€” The ID number of the task being monitored ๐Ÿ”ข.
    • prio โ€” The realtime priority of the task being monitored ๐Ÿฅ‡.
    • policy โ€” The scheduling policy of the task being monitored ๐Ÿ“‹.
    • Command โ€” The command name of the task ๐ŸŽฌ.
  • -r โ€” Report page faults and memory utilization ๐Ÿง .

When you're looking at individual tasks, you can see:

  • UID โ€” The real user ID number of the task being monitored ๐Ÿ†”.
  • USER โ€” The name of the real user who owns the task being monitored ๐Ÿง‘.
  • PID โ€” The ID number of the task being monitored ๐Ÿ”ข.
  • minflt/s โ€” The total number of minor faults the task made per second. These are the ones that didn't need a memory page loaded from disk ๐Ÿ™Œ.
  • majflt/s โ€” The total number of major faults the task made per second. These are the ones that did need a memory page loaded from disk ๐Ÿ˜ฌ.
  • VSZ โ€” Virtual Size: the virtual memory usage of the entire task, in kibibytes ๐ŸŒŒ.
  • RSS โ€” Resident Set Size: the non-swapped physical memory the task is using, in kibibytes ๐Ÿ’พ.
  • %MEM โ€” The task's currently used share of the available physical memory ๐Ÿฅง.
  • Command โ€” The command name of the task ๐ŸŽฌ.

When you're looking at global stats for tasks and all their children, you can see:

  • UID โ€” The real user ID number of the task being monitored, along with its children ๐Ÿ†”.
  • USER โ€” The name of the real user who owns the task being monitored, along with its children ๐Ÿง‘.
  • PID โ€” The ID number of the task being monitored, along with its children ๐Ÿ”ข.
  • minflt-nr โ€” The total number of minor faults made by the task and all of its children, collected during the interval ๐Ÿซง.
  • majflt-nr โ€” The total number of major faults made by the task and all of its children, collected during the interval ๐Ÿซ .
  • Command โ€” The command name of the task being monitored, along with its children ๐ŸŽฌ.
  • -s โ€” Report stack utilization ๐Ÿฅž. The values you can see are:
    • UID โ€” The real user ID number of the task being monitored ๐Ÿ†”.
    • USER โ€” The name of the real user who owns the task being monitored ๐Ÿง‘.
    • PID โ€” The ID number of the task being monitored ๐Ÿ”ข.
    • StkSize โ€” The amount of memory in kibibytes reserved for the task as stack, but not necessarily used ๐Ÿ“ฆ.
    • StkRef โ€” The amount of memory in kibibytes actually used as stack and referenced by the task ๐Ÿ‘€.
    • Command โ€” The command name of the task ๐ŸŽฌ.
  • -T { TASK | CHILD | ALL } โ€” This decides what pidstat monitors ๐Ÿ”. The TASK keyword reports stats for individual tasks, and that's the default ๐Ÿ . The CHILD keyword reports stats globally for the selected tasks and all their children ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ง. The ALL keyword does both: individual tasks and the global stats for the selected tasks and their children ๐ŸŒˆ.
Note: Global stats for tasks and all their children aren't available for every pidstat option ๐Ÿ™…โ€โ™€๏ธ. Also, these stats aren't necessarily relevant to the current time interval. A child process's stats only get collected when it finishes or gets killed โšฐ๏ธ.
  • -t โ€” Also show stats for the threads linked to the selected tasks ๐Ÿงต.

This option adds these values to the reports:

  • TGID โ€” The ID number of the thread group leader ๐Ÿ‘‘.
  • TID โ€” The ID number of the thread being monitored ๐Ÿชก.
  • -U [ username ] โ€” Show the real user name of the tasks being monitored instead of the UID ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘. If you give username, only the tasks that belong to that user will show up ๐Ÿ’.
  • -u โ€” Report CPU utilization ๐Ÿ”ฅ.

When you're looking at individual tasks, you'll see:

  • UID โ€” The real user ID number of the task being monitored ๐Ÿ†”.
  • USER โ€” The name of the real user who owns the task being monitored ๐Ÿง‘.
  • PID โ€” The ID number of the task being monitored ๐Ÿ”ข.
  • %usr โ€” The percentage of CPU the task used while running at the user level (application), with or without nice priority ๐ŸŽง. Heads up: this does NOT include time spent running a virtual processor ๐Ÿ™….
  • %system โ€” The percentage of CPU the task used while running at the system level (kernel) ๐Ÿ› ๏ธ.
  • %guest โ€” The percentage of CPU the task spent in a virtual machine, running a virtual processor ๐Ÿ–ฅ๏ธ.
  • %wait โ€” The percentage of CPU the task spent waiting to run โณ.
  • %CPU โ€” The total percentage of CPU time the task used ๐Ÿ’ฏ. On an SMP system, the task's CPU usage gets divided by the total number of CPUs if you've put -I on the command line ๐Ÿงฎ.
  • CPU โ€” the processor number the task is hanging out on ๐Ÿง 
  • Command โ€” the command name of the task โœจ

When you're looking at global stats for a task and all of its children, you might see these ๐Ÿ’œ

  • UID โ€” the real user ID of the task being watched, along with its children ๐ŸŽ€
  • USER โ€” the name of the real user who owns that task and its children ๐Ÿซถ
  • PID โ€” the ID number of the task being watched, children included ๐Ÿ”ข
  • usr-ms โ€” the total milliseconds the task and its children spent running at the user level (apps ๐Ÿ’…), with or without nice priority, during the interval. Heads up: this does NOT count time spent running a virtual processor ๐Ÿ™…โ€โ™€๏ธ
  • system-ms โ€” the total milliseconds the task and its children spent at the system level (kernel ๐Ÿงš), during the interval
  • guest-ms โ€” the total milliseconds the task and its children spent inside a virtual machine, running a virtual processor ๐ŸŒˆ
  • Command โ€” the command name of the task, plus its children ๐Ÿ“

  • -V โ€” prints the version number, then exits. Simple, iconic, done ๐Ÿ‘‘
  • -v โ€” reports values from some kernel tables ๐Ÿฆ‹ You'll see these fields:
    • UID โ€” the real user ID of the task being monitored
    • USER โ€” the name of the real user who owns the task being monitored
    • PID โ€” the ID number of the task being monitored
    • threads โ€” how many threads belong to the current task ๐Ÿงต
    • fd-nr โ€” how many file descriptors belong to the current task ๐Ÿ“‚
    • Command โ€” the command name of the task
  • -w โ€” reports task switching activity ๐Ÿ”„ Heads up: this one only works on kernels 2.6.23 and later โš ๏ธ You'll see:
    • UID โ€” the real user ID of the task being monitored
    • USER โ€” the name of the real user who owns the task being monitored
    • PID โ€” the ID number of the task being monitored
    • cswch/s โ€” how many voluntary context switches the task made per second. That's when a task blocks itself because it needs a resource that isn't available right now ๐Ÿ˜ด
    • nvcswch/s โ€” how many non-voluntary context switches the task made per second. That's the drama one: a task runs for its whole time slice and then gets forced to give up the processor ๐Ÿ˜ค
    • Command โ€” the command name of the task

โœจ ENVIRONMENT โœจ

okay so pidstat pays attention to these environment variables, so you can customise your vibe ๐Ÿ’–

  • S_COLORS โ€” by default, stats show up in color when the output is going to a terminal ๐ŸŒˆ Use this one to change things. The possible values are never, always or auto (and auto is the same as the default, so you're already set ๐Ÿซถ). Also, don't read into the colors! Red or yellow doesn't mean something is wrong, it just marks different ranges of values ๐Ÿ’…
  • S_COLORS_SGR โ€” this one sets the colors and other text attributes used to display stats in the terminal ๐ŸŽจ Its value is a colon-separated list of capabilities, and the default is I=32;22:N=34;1:W=35;1:X=31;1:Z=34;22. The capabilities you can use are:
    • I= โ€” the SGR (Select Graphic Rendition) substring for item values, like PID, UID or CPU number ๐Ÿ”ข
    • N= โ€” the SGR substring for non-zero statistics values and for task names ๐Ÿ’œ
    • W= (or M=) โ€” the SGR substring for percentage values in the range from 75% to 90% (or in the range 10% to 25%, depending on what the metric means) โš ๏ธ
    • X= (or H=) โ€” the SGR substring for percentage values greater than or equal to 90% (or lower than or equal to 10%, depending on the metric) ๐Ÿšจ
    • Z= โ€” the SGR substring for zero values and for thread names ๐Ÿค
  • S_TIME_FORMAT โ€” if this variable exists and its value is ISO, the current locale gets ignored when the date is printed in the report header ๐Ÿ—“๏ธ pidstat will use the ISO 8601 format (YYYY-MM-DD) instead, and the timestamp will be ISO 8601 compliant too โœจ

โœจ EXAMPLES โœจ

okay now for the fun part, bestie ๐ŸŽ€ here are some combos you can copy:

pidstat 2 5

Shows five reports of CPU stats for every active task on the system, at two second intervals ๐Ÿ’…

pidstat -r -p 1643 2 5

Shows five reports of page faults and memory stats for PID 1643, at two second intervals ๐Ÿง 

pidstat -C "fox|bird" -r -p ALL

Shows global page faults and memory stats for every process whose command name includes the string "fox" or "bird" ๐ŸฆŠ๐Ÿฆ

pidstat -T CHILD -r 2 5

Shows five reports of page faults stats at two second intervals for the child processes of all tasks on the system ๐Ÿ‘ถ Only child processes with non-zero stats get displayed, so no clutter ๐Ÿซถ

โœจ BUGS โœจ

โš ๏ธ the /proc filesystem must be mounted for pidstat to work at all. No /proc, no vibes ๐Ÿ’€

Even though pidstat shows units that look like kilobytes (kB), megabytes (MB)..., it's actually using kibibytes (kiB), mebibytes (MiB)... ๐Ÿค“ A kibibyte is 1024 bytes, and a mebibyte is 1024 kibibytes. Lowkey a plot twist ๐Ÿ™ˆ

โœจ FILES โœจ

/proc is where the various files with system statistics live ๐Ÿ“๐Ÿงš

โœจ AUTHOR โœจ

Sebastien Godard (sysstat <at> orange.fr) ๐Ÿ‘‘ the legend behind it ๐Ÿซถ

โœจ SEE ALSO โœจ

sar(1), top(1), ps(1), mpstat(1), iostat(1), vmstat(8) โ€” go check these out, they're giving ๐Ÿฆ‹

For more, peep https://github.com/sysstat/sysstat and https://sysstat.github.io/ ๐ŸŒธ


bestie, that's the whole thing ๐Ÿ’– pidstat, sysstat-approved, from the Linux crew, last updated JANUARY 2025, and you are officially a PIDSTAT(1) expert now ๐ŸŽ€โœจ๐Ÿ‘‘