Viewing process utilization on Linux hosts with pidstat

While playing around with my Debian 5.0 host last week, I came across the pidstat utility. Pidstat allows you to display a number of statistics for processes running on a system (and threads inside that process), which can be incredibly useful for troubleshooting performance problems. To use pidstat to get a breakdown of how a given process is using the processors on a system, pidstat can be run with the “-p” option and the process ID to interrogate:

$ pidstat -p 3297 2

Linux 2.6.26-1-686 (disarm) 	03/07/2009 	_i686_

08:07:18 AM       PID   %user %system    %CPU   CPU  Command
08:07:20 AM      3297   11.06   74.37   85.43     0  dd
08:07:22 AM      3297   13.00   70.00   83.00     0  dd
08:07:24 AM      3297   10.95   72.64   83.58     0  dd



If you are looking to see how much I/O a specific process is responsible for, you can run pidstat with the “-d” option:

$ pidstat -d -p 3288 2

Linux 2.6.26-1-686 (disarm) 	03/07/2009 	_i686_

08:06:35 AM       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
08:06:37 AM      3288      3.98 113319.40      0.00  dd
08:06:39 AM      3288      4.00 112514.00      0.00  dd
08:06:41 AM      3288      4.00  81454.00      0.00  dd



And finally, to view paging activity per process, you can run pidstat with the “-r” option (and optionally the “-t” flag if you want to see thread activity):

$ pidstat -r -t -p 3338 2

Linux 2.6.26-1-686 (disarm) 	03/07/2009 	_i686_

08:10:20 AM       PID       TID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
08:10:22 AM      3338        -       0.00      0.00    3180    596   0.23  dd
08:10:22 AM        -       3338      0.00      0.00    3180    596   0.23  |__dd

08:10:22 AM       PID       TID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
08:10:24 AM      3338        -       0.00      0.00    3180    596   0.23  dd
08:10:24 AM        -       3338      0.00      0.00    3180    596   0.23  |__dd

08:10:24 AM       PID       TID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
08:10:26 AM      3338        -       0.00      0.00    3180    596   0.23  dd
08:10:26 AM        -       3338      0.00      0.00    3180    596   0.23  |__dd



Pidstat is pretty darn cool, and I will definitely be using this in the future! Nice!

2 Comments

Balwinder S Dheeman  on August 14th, 2010

Aye! you forget to mention how to get this ‘pidstat’ thingy i.e. which package provides the ‘pidstat’ ;-)

Everyone is not smart enough to search debian and, or other sites; only few care to use google :-(

Anyway, I for one would like to inform user that the package ‘sysstat’ provides the said utility on almost all Linux distributions :-)

Antonello  on December 23rd, 2010

pidstat is provided by the package ‘sysstat’ (from version 8 onwards I believe) and relies on I/O process accounting which is available in 2.6.20 or later kernels

Leave a Comment