title: Linux best way in two-way IPC in C
body: <p>I haved a problem to complete my example when asked <a href="https://stackoverflow.com/questions/27259672/linux-c-starting-the-child-program-in-new-process-and-ipc">this question</a>.<br>
  I searched for ways of implementing IPC in Google.<br>
  I can't decide which way is best for write my program.<br>
  I tried lots of implementations and have lots of complications with them.</p>
  
  <p>I want to have:<br>
   1. parent process to manage child process - OK ( template )<br>
   2. parent and children must have implemented callback for new message signal<br>
   3. one process do not know message size from other process ( char * )</p>
  
  <p>My code:</p>
  
  <p>header.h:</p>
  
  <pre><code>#ifndef MESSAGES_H
  #define MESSAGES_H
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  // need here: some includes and definitions
  
  inline char * read_message( /* need here: some params */ ) {
      // need here: read message function
  }
  
  inline char * send_message( /* need here: some params */ ) {
      // need here: send message function
  }
  #endif
  </code></pre>
  
  <p>parent.c:</p>
  
  <pre><code>#include "header.h"
  
  // parent specyfic includes and definitions
  
  void on_message( /* need here: some parameters */ ) {
      char *message = read_message( /* need here: some other parameters */ );
      // do something with / if message etc.
  }
  
  int runChild(key) {
      int pid = fork();
      if (pid == 0) {
          execl("./child", "./child", /* params here */, null);
      }else{
          return pid;
      }
  }
  
  int main(int argc, char *argv[]) {
      // need here: prepare IPC
      // need here: on new message event call function "on_message"
      int childPid = runChild(key);
      // loop - for example: gtk_main()
      // need here: close childs
  }
  </code></pre>
  
  <p>child.c</p>
  
  <pre><code>#include "header.h"
  
  // child specyfic includes and definitions
  
  void on_message( /* need here: some parameters */ ) {
      char *message = read_message( /* need here: some other parameters */ );
      // do something with / if message etc.
  }
  
  int main(int argc, char *argv[]) {
      // need here: prepare IPC
      // need here: on new message event call function "on_message"
      int pid = getpid();
      int parentPid = getppid();
      printf("Child with pid %d is ready for messages from parent with pid: %d", pid, parentPid);
      // event loop - for example: gtk_main()
  }
  </code></pre>
  
  <p>Which IPC way is better in that example program template ( safe and speed ) ?
  Can you share a really simple example that matches the above template ?</p>