title: Free shared memory on signal interrupt
body: <p>I'm writing a program in C and I'm creating a couple of child processes which use POSIX shared memory.
  Now I am trying to handle the case when the program is interrupted by signal like SIGINT.
  I know, I need to install signal function and it isn't good to free resources directly in signal handler because of the inconsistency of the code so it is necessary just to switch the boolean flag.
  Meanwhile my main code in is loop until the flag is switched.</p>
  
  <p>So it goes something like this:</p>
  
  <pre><code> bool signal_interrupt = false;     
  
   void sig_handler(int sig_num)
   {
     signal_interrupt = true;
   }
  
   int main(void)
   {
     while (!signal_interrupt)
     {
       /* code, arguments processing, functions calling...*/
       signal_interrupt = true;
     }
   } 
  </code></pre>
  
  <p>My problem is that I cannot figure how to release the resources in some function of the program. Should the code of the function be in the same loop as shown in the main func? How the program reacts on signal interrupt? It returns from the current function to main and if it finds signal function its handler is called?
  Thanks for any advice, I would really like to understand this.</p>