<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 23/11/10 22:23, Nix wrote:
<blockquote cite="mid:87y68jsmqc.fsf@spindle.srvr.nix" type="cite">
  <pre wrap="">On 23 Nov 2010, Karanbir Singh told this:
  </pre>
  <blockquote type="cite">
    <pre wrap="">As another example, when asked to find per-process blockdev i/o rate, 
only 1 out of 8 people actually looked in /proc/<id>/; a couple 
    </pre>
  </blockquote>
  <pre wrap="">
I'm sorry, where is this? I just hunted for it and can't see anything
relating to per-process blockdev I/O there. I had no idea Linux tracked
such things on a per-process basis (in fact I can remember patches to do
such things being rejected in the past).

Of course what I do now is dig into the source tree, and find that the
third-from-last /proc/{pid}/stat entry is the per-task I/O delay figure,
which may be what you referred to. This is seriously obscure stuff: it
was added in 2006, but the only distro which appears to have packaged
the userspace side of this is OpenSUSE. I can't find any sign of an
upstream source tree at all.
  </pre>
</blockquote>
I wrote this very short script a few months ago to identify processes
by state and CPU, it works on RHEL5 (2.6.18):<br>
<p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">#!/bin/sh<br>
pid=${1}<br>
if [ ! -z "$pid" ]; then<br>
  read pid tcomm state ppid
pgid sid tty_nr tty_pgrp flags
min_flt cmin_flt maj_flt cmaj_flt utime stime cutime cstime priority
nice
num_threads start_time vsize mm rsslim start_code end_code start_stack
eis eip
pending blocked sigign sigcatch wchan oul1 oul2 exit_signal cpu
rt_priority
policy ticks < /proc/$pid/stat<br>
  echo "Pid $pid $tcomm is
in state $state on CPU
$cpu"<br>
</span></font><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">fi</span></font><br>
</p>
Which is general-purpose enough to add $blocked (and all sorts of other
detail, like $num_threads) to the output if required. I've found it
quite handy a few times recently - share and enjoy! It takes its
definitions from o_task_stat in linux-2.6.18.x86_64/fs/proc/array.c.<br>
<blockquote cite="mid:87y68jsmqc.fsf@spindle.srvr.nix" type="cite">
  <pre wrap="">Anyone who correctly answers this question is a kernel deity, or
Shailabh Nagar :)
  </pre>
</blockquote>
I am neither. Like you, I just read the source. I wouldn't expect
anyone to come up with this kind of level of detail in an interview
situation though.<br>
</body>
</html>