title: Linux kernel - wait queues
body: <p>I'm reading "Linux kernel development 3rd edition by Robert Love" to get a general idea about how the Linux kernel works..(2.6.2.3)</p>
  
  <p>I'm confused about how wait queues work for example this code:</p>
  
  <pre><code>    /* ‘q’ is the wait queue we wish to sleep on */ 
  DEFINE_WAIT(wait);
  add_wait_queue(q, &amp;wait); 
  
  while (!condition) { /* condition is the event that we are waiting for */
      prepare_to_wait(&amp;q, &amp;wait, TASK_INTERRUPTIBLE); 
      if (signal_pending(current))
          /* handle signal */ 
        schedule();
      }
  
  finish_wait(&amp;q, &amp;wait);
  </code></pre>
  
  <ul>
  <li><p>I want to know which process is running this code? is it a kernel thread? whose process time is this? </p></li>
  <li><p>And also in the loop, while the condition is still not met we will continue sleeping and call schedule to run another process <strong>the question is</strong> when do we return to this loop?</p></li>
  <li><p>The book says that when a process sleeps, it's removed from our run queue, else it would be waken and have to enter a busy loop...</p></li>
  <li>Also says: "sleeping should always be handled in a loop that ensures that the condition for which the task is waiting has indeed occurred."</li>
  </ul>
  
  <p>I just want to know in what context is this loop running? </p>
  
  <p>Sorry if this is a stupid Question. I'm just having trouble seeing the big pic</p>