1

I am writing a script and I need to find a file in which statistics for a single process/pid/service's iowait are stored. Is there any such file at all on Debian-based distributions?

Nor /proc/<pid>/stat, neither /proc/<pid>/io have any stat for iowait, according to the man pages. I am aware I can parse the output of other tools like iotop, sar, and etc., however, parsing stdout of external commands is a performance issue which I have to avoid.

Note: I am aware of /proc/stat and the meaning of its contents. I need the iowait stat for a single process, not for the whole CPU or a core.

2

Theoretically you can obtain iowait per process from /proc/[pid]/stat, since from corresponding block of PROC(5) we read:

(42) delayacct_blkio_ticks  %llu  (since Linux 2.6.18)
     Aggregated block I/O delays, measured in clock ticks (centiseconds).

I have no idea what the delayacct_blkio_ticks means practically. Anyway, the only man proc will be useful to you.

There is related question, check it: Measuring block I/O delays using proc FS

Additionally, pay your attention to notes for /proc/stat in the per CPU iowait block:

  1. The CPU will not wait for I/O to complete; iowait is the time that a task is waiting for I/O to complete. When a CPU goes into idle state for outstanding task I/O, another task will be scheduled on this CPU.
  2. On a multi-core CPU, the task waiting for I/O to complete is not running on any CPU, so the iowait of each CPU is difficult to calculate.
  3. The value in this field may decrease in certain conditions.

You can get iowait data per CPU from /proc/stat. On my Ubuntu 18.04 in the /proc/stat there is such the part:

cpu  2752162 16054 941158 49212025 789607 0 217089 0 0 0
cpu0 1397207 7767 500620 24623046 407078 0 70574 0 0 0
cpu1 1354955 8286 440538 24588978 382529 0 146515 0 0 0

The fifth column besides cpus column is iowait value in my particular case. The number of columns and its meaning can be various depending on your kernel in use.

To get every column exact meaning you have to look at your documentation. In Ubuntu install linux-doc package first:

sudo apt install linux-doc

and look at man proc:

man proc

There is part with exact /proc/stat explanation for every column.

Read additionally How to read the Linux /proc/stat file to know how to calculate values.

In CentOS it's necessary to install kernel-doc package:

yum install kernel-doc

then read the file:

/usr/share/doc/kernel-doc/Documentation/filesystems/proc.txt
| improve this answer | |
  • I am aware of what /proc/stat is and of its contents. However, I've explicitly said that I need iowait for a single process, not for a core. Thank you for the detailed answer nonetheless. – Fanatique Jul 30 '18 at 10:00
  • @Fanatique I have edited my answer, please, check it. – Bob Jul 30 '18 at 11:49
  • I'll have to do with that. Anyways, great! Thank you, I have no idea how I've missed that in the man pages.. Guess I haven't been reading enough thoroughly. – Fanatique Jul 30 '18 at 12:02
  • @Fanatique You're welcome! – Bob Jul 30 '18 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.