title: Total number of bytes read/written by a Linux process and its children
body: <p>I would like to print the total number of bytes read/written by a Linux process. For example, I run</p>
  
  <pre><code>gcc -c a.c
  </code></pre>
  
  <p>and would like to see how many bytes in total did GCC, including its children, request from the Linux kernel and how many bytes they sent to the kernel.</p>
  
  <p>Incomplete solutions to this problem are:</p>
  
  <ul>
  <li><p>The fields <code>rchar</code> and <code>wchar</code> in <code>/proc/PID/io</code> show the number of read/written bytes so far. It does not account for child processes. It is lost as soon as the process terminates.</p></li>
  <li><p>A tool such as <code>strace</code> can be used to print out the syscalls of a process and its children (such as: <code>read</code>, <code>write</code> syscalls), but it is unable to aggregate the number of bytes read/written.</p></li>
  </ul>
  
  <p>How to print the total number of bytes read/written by a Linux process and its child processes?</p>