#!/usr/bin/perl -w #pio: This script provides I/O-related counters for all processes to be used by topio. #(C) Yong Huang, 2010 #yong321.freeshell.org/freeware/pio.html chdir "/proc"; opendir PROC, "." or die "Can't open /proc: $!"; while (defined ($file = readdir PROC)) { if ($file =~ /^\d+$/) #each file is a pid { open IO, $file."/io" or die "Can't open file /proc/$file/io: $!"; while (defined ($_=)) { last if /^rchar: 0/; #skip pseudo procs that are kernel threads; their rchar must be 0 print "$file\t" . qx(cat $file/cmdline) . "\t" if /^rc/; #print pid when first line of io file chomp; print substr $_,(index $_,":")+2; print (/^c/ ? "\n" : "\t") ; #line begins with cancelled_write_bytes } close IO; } } close PROC; #As of this writing, /proc//io is like #rchar: 6297 #wchar: 0 #syscr: 15 #syscw: 0 #read_bytes: 0 #write_bytes: 0 #cancelled_write_bytes: 0