title: How to know which processor is being used by a process?
body: <p>In a multithreaded environment, I want to exactly know which processor is being used by my process.</p>
  <p>I looked into the source code of top and htop. The problem with the top/htop is that it gets the total time (from <code>/proc/stat</code> and <code>/proc/[pid]/stat</code>) and divides it by the number of CPUs irrespective of the load that is distributed among the other processors.</p>
  <p>If the total %CPU is 350% theoretically we know at least 4 processors are being used. The top is generalizing this and doesn't &quot;accurately&quot; quantify the per processor usage.</p>
  <p>350% can imply in different ways:</p>
  <pre><code>Processor 1: 100%
  Processor 2: 75%
  Processor 3: 75%
  Processor 4: 100%
  
  Processor 1: 75%
  Processor 2: 100%
  Processor 3: 100%
  Processor 4: 75%
  </code></pre>
  <p>The <code>/proc/[pid]/stat</code> gives the last processor used but doesn't which processors are being used by a process.</p>
  <p>Any idea how to accurately capture which processor is being by the process?</p>
  <p>My end goal is to find out how efficiently my algorithm is using the machine.</p>