title: using signal and alarm as timeouts in C
body: <p>First thing, I'm new at C. I've inherited some legacy C code. In in this application the time outs aren't working correctly. It uses signal and alarm to create a timeout. I've read up on both and I'm still having a problem.  </p>
  
  <pre><code>signal(SIGALRM, timeouthandler);
  alarm(3);
  ...(connection to a server that may hang)...
  
  alarm(0);
  
  timeouthandler(){
  ...(connection to a server that may hang)...
  } 
  </code></pre>
  
  <p>Now this works fine until I have to add a time out to a different section of the code.</p>
  
  <pre><code>signal(SIGALRM, timeouthandler2);
  alarm(3);
  ...(log the time out)...
  
  alarm(0);
  
  timeouthandler2(){
  ...(log the time out)...
  }
  </code></pre>
  
  <p>Why is my second timeout not working? What is the connect between signal and alarm? and is there a cleaner (not to complicated) way of doing this. Also I'm going to need another timeout handler that contains both of these timeouts. Thanks!! </p>
  
  <p><strong>EDIT</strong>: ok, so it looks like I can't have a two timeouts going at once. Let me explain what I'm trying to do. I have a list of servers that I want to connect to. I want each connect to have 3 seconds to connect and if not to time out. Then I also want a <code>global</code> time out for the list of servers so that if the total time for all the connection's time go over 12 second it times out and moves on. Is there another way I can do this? </p>