-1

iostat screenshot

I need to IO utilization for Process by Process ID without using any tool like iostat,iotop etc.

Can any please help me to get IO utilization using info files using /proc/PID?

Thanks in ADV.

HBruijn
  • 72,524
  • 21
  • 127
  • 192
Monti Chandra
  • 111
  • 1
  • 3

1 Answers1

3

You can get the io stats by process from proc. The information is available under /proc/[PID]/io

The information is stored like this:

cat /proc/2039/io

rchar: 293898605
wchar: 63376205
syscr: 114996
syscw: 51573
read_bytes: 98484224
write_bytes: 29159424
cancelled_write_bytes: 8192

The definitions of the fields are:

rchar: number of bytes the process read, using any read-like system call (from files, pipes, tty...).

wchar: number of bytes the process wrote using any write-like system call.

syscr: number of read-like system call invocations that the process performed.

syscw: number of write-like system call invocations that the process performed.

read_bytes: number of bytes the process directly read from disk.

write_bytes: number of bytes the process originally dirtied in the page-cache (assuming they will go to disk later).

cancelled_write_bytes: number of bytes the process "un-dirtied" - e.g. using an "ftruncate" call that truncated pages from the page-cache.

source

For further information on /proc/[pid]/io, take a look at the documentation or this Stack Overflow Q&A.

If you want to calculate the utilization you will also need stats from /proc/diskstats. The definition of the fields is defined in the Kernel documentation.

However as you can see /proc/diskstats users different metrics from /proc/[PID]/io which means you will need a lot of calculation to get utilization metrics. That is why I don't think it is a very fruitful idea to calculate these metrics manually.

iBug
  • 1,048
  • 2
  • 9
  • 21
Henrik Pingel
  • 8,676
  • 2
  • 24
  • 38