title: Message queue not receiving information as expected
body: <p>I'm coding a program and I wanted to use a message queue in order to schedule the program ending. This is a schema of the code:</p>
  <pre><code>typedef struct {
      long id;
      int num;
  }Message;
  
  int disconnect = 0;
  
  void disconnection() {
      disconnect = 1;
  }
  
  int main () {
     
      //...
  
      int n = fork();
      int id_queue = msgget(ftok(&quot;connection.h&quot;, 66), 0600|IPC_CREAT);
  
      switch(n) {
  
          case 0: //child process
  
              Message message;
              message.id = 1;
              message.num = 0;
  
              while (1) {
                  // ...
  
                  msgrcv(id_queue, (struct msgbuf *) &amp;message, sizeof(int), 1, IPC_NOWAIT);
  
                  if (message.num == 1) break;
              }
  
              write(1, &quot;Exit successfull\n&quot;, strlen(&quot;exit successfulll&quot;)); //The child process does not reach this line
  
              msgctl(id_queue, IPC_RMID, (struct msqid_ds *)NULL);
          break;
  
          default: //main process
              signal(SIGINT, disconnection);
  
              while (!disconnect) { /* ... */ }
  
              Message msg;
              msg.id = 1;
              msg.num = 1;
  
              msgsnd(id_queue, (struct msgbuf *) &amp;msg, sizeof(int), IPC_NOWAIT);
  
              wait(NULL); //waiting for child process to end
          break;
  
  }
  </code></pre>
  <p>As you can see, the program works until I interrupt it with a <code>SIGINT</code>. The disconnection process in order to end the child process is to send a message that is just an <code>int</code> and if it's <code>1</code>, child process loop should break. I have tested it and it doesn't enter (doesn't print the <code>write</code> after the <code>while(1)</code> loop) so I'm figuring out I have some errors sending or receiving the data through the message queue.</p>
  <p>What's wrong?</p>
  <p>Also, the program ends after I send <code>SIGINT</code> interruption and <code>wait(NULL)</code> is not waiting for child process to end, as the <code>write</code> doesn't print through the screen...</p>