title: Exiting gracefully from a multithreaded process
body: <p>I'm running a multi-threaded C program (process?) , making use of semaphores &amp; pthreads. The threads keep interacting, blocking, waking &amp; printing prompts on stdout continuously, without any human intervention. I want to be able to exit this process (gracefully after printing a message &amp; putting down all threads, not via a crude <code>CTRL+C</code> <code>SIGINT</code>) by pressing a keyboard character like #. </p>
  
  <p>What are my options for getting such an input from the user?</p>
  
  <p>What more relevant information could I provide that will help to solve this problem?</p>
  
  <p><strong>Edit:</strong>
  All your answers sound interesting, but my primary question remains. How do I get user input, when I don't know which thread is currently executing? Also, semaphore blocking using <code>sem_wait()</code> breaks if signalled via <code>SIGINT</code>, which may cause a deadlock.</p>