title: Posix message queue issue about sending message
body: <p>I am trying to send a message from child process to parent process using POSIX message queues. I created the message queue before I created children using fork(). My code is supposed to take words from the linked list and send them to the parent. However, when I call the mq_send function to send data, program gets stuck in the function, tries to take input from the console and never stops. I have been working on this problem for more than day and I could not figure out how to do it. I checked the other parts of the code and they all work. Only the mq_send function causes a problem. Can somebody tell me what is the problem here? Maybe I am missing something. The code is below.</p>
  <p>Note: I cannot include all the code here. Only parts relevant to the problem is here. Also, this is my first question in stackoverflow so I am sorry about possible formatting errors.</p>
  <p>Edit: The code cannot be compiled because I did not add all the parts. My question is only based on the last while loop of the code where the message is sent. That is where the code gets stuck.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stddef.h&gt;
  #include &lt;math.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;mqueue.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/ipc.h&gt; 
  #include &lt;sys/msg.h&gt; 
  #include &lt;unistd.h&gt;
  
  struct Node {
      char value[1024];
      int count;
      struct Node* next;
  };
  
  struct dataPackage {
      char word[1024];
      int count;
  };
  
  
  int main(int argcount, char** argvalues) {
      struct Node* headList[atoi(argvalues[1])];      // an array to hold linked lists   
      
      // creating fileCount number of linked lists and storing them
      for ( int i = 0; i &lt; atoi(argvalues[1]); i++ ) {
          headList[i] = NULL;
      }
  
      // creating message queues
      mqd_t mqList[fileCount];
      char queueNames[5][1024];
      int n;
      // creating different names for different message queues
  
      strcpy(queueNames[0], &quot;/queue1&quot;);
      strcpy(queueNames[1], &quot;/queue2&quot;);
      strcpy(queueNames[2], &quot;/queue3&quot;);
      strcpy(queueNames[3], &quot;/queue4&quot;);
      strcpy(queueNames[4], &quot;/queue5&quot;);
  
      // creating the message queues
      for (int i = 0; i &lt; atoi(argvalues[1]); i++ ) {
          mqList[i] = mq_open(queueNames[i], O_RDWR | O_CREAT, 0666, NULL ); 
          printf(&quot;%i\n&quot;, mqList[i]); 
      }
  
      // creating child processes to process input files
      
      for (int i = 0; i &lt; atoi(argvalues[1]); i++ ) {
          
          // creating a child process
          pid_t pid = fork();
          
          // child processes process seperate files
          if (pid == 0 ) {
              //printf(&quot;Before file process\n&quot;);
              // processing the file and creating the sorted linked lists
              processFile(fileNames[i], &amp;headList[i]);
              
              // send linked list contents to parent process below
              struct dataPackage package;
              struct Node* tempHead = headList[i];
              
              while (tempHead != NULL) {
                  // creating a package to send it to the parent process
                  package.count = tempHead-&gt;count;
                  strcpy(package.word, tempHead-&gt;value);
                  
                  // !!!!!this is the part where the program gets stuck!!!!!!!!
                  n = mq_send(mqList[i], (char*) &amp;package, sizeof(struct dataPackage), 0);
                  tempHead = tempHead -&gt; next;
              }
              // creating a message that will indicate the end of message queue
              package.count = -10;
              strcpy(package.word, &quot;stop&quot;);
              n = mq_send(mqList[i], (char *) &amp;package, sizeof(struct dataPackage), 0);
              exit(0);
          }   
          else {
              wait(NULL);
          }
      }
  </code></pre>