title: How are nice priorities and scheduler policies related to process (thread?) IDs in linux?
body: <p>I am investigating how to have my Linux desktop experience remain smooth and interactive while I run CPU intensive tasks in the background.  Here is the sample program (written in Java) which I am using to simulate CPU load:</p>
  
  <pre><code>public class Spinner {
      public static void main(String[] args)
      {
          for (int i = 0; i &lt; 100; i++) {
              (new Thread(new Runnable() {
                      public void run() {
                          while (true);
                      }
              })).start();
          }
      }
  }
  </code></pre>
  
  <p>When I run this on the command line, I notice that the interactivity of my desktop applicaitons (e.g. text editor) drops significantly.  I have a dual core machine, so I am not suprised by this.</p>
  
  <p>To combat this my first thought was to <em>nice</em> the process with <code>renice -p 20 &lt;pid&gt;</code>.  I found however that this doesn't have much affect.  I instead have to renice all of the child processes with something like <code>ls /proc/&lt;pid&gt;/task | xargs renice 20 -p --</code> which has a much greater effect.</p>
  
  <p>I am very confused by this, as I would not expect threads to have their own process IDs.  Even if they did I would expect <code>renice</code> to act on the entire process, not just the main thread of the process.</p>
  
  <p><strong>Does anyone have a clear understanding of what is happening here?</strong>  It appears that each thread is actually a seperate process (at least it has a valid PID).  I knew that historically Linux worked like this, but I believed NPTL fixed that years ago.</p>
  
  <p>I am testing on RHEL 5.4 (linux kernel 2.6.18).</p>
  
  <p>(As an aside.  I notice the same effect if I try to use <code>sched_setscheduler(&lt;pid&gt;, SCHED_BATCH, ..)</code> to try to solve this interactivity problem.  Ie, I need to make this call for all the "child" processes I seee in <code>/proc/&lt;pid&gt;/task</code>, it is not enough to perform it once on the main program pid.)</p>