title: Understanding sigwait() and how it sets parameters
body: <p>The man page for sigwait() is a big confusing to me. The signature for sigwait is</p>
  
  <pre><code> int sigwait(const sigset_t *set, int *sig);
  </code></pre>
  
  <p>Say I have code similar to the following</p>
  
  <pre><code> sigset_t wset;
   sigemptyset(&amp;wset);
   sigaddset(&amp;wset,SIGHUP);
   sigaddset(&amp;wget,SIGINT);
   sigaddset(&amp;wget,SIGTERM);
   int sig;
   sigwait(&amp;wset,&amp;sig);
  </code></pre>
  
  <p>If I understand correctly, this will wait on a signal to be sent. If the signal is found in the signal set (i.e. <strong>sigset_t wset</strong>), it will set the signal number (i.e. <strong>int sig</strong>), as found in the set (i.e. <strong>SIGHUP, SIGINT, SIGTERM</strong> in this example). Otherwise, it will set the signal number to 0. Is my understanding correct?</p>
  
  <p>I would try this out, but I don't have access to a compiler at the moment.</p>
  
  <p>edit: for further clarification</p>
  
  <p>Ok so, I send one of the signals above:</p>
  
  <pre><code> int res = sigwait(&amp;wset,&amp;sig);
   // res = 0, sig = SIGHUP, SIGINT, or SIGTERM
  </code></pre>
  
  <p>And I send a signal not included in the set:</p>
  
  <pre><code>int res = sigwait(&amp;wset,&amp;sig);
  // res = EINVAL (i.e. non-zero) and don't worry about sig
  </code></pre>
  
  <p>Is this correct?</p>