title: How to communicate from children process(exec) with parent through pipe()?
body: <p>I have these two files and i call exec.c from main.c using exec(). As far as I understand exec.c should inherit the pipe but it says there is no link pipe in exec.c. What is the problem here?</p>
  <p>main.c</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  #define die(e)                      \
      do                              \
      {                               \
          fprintf(stderr, &quot;%s\n&quot;, e); \
          exit(EXIT_FAILURE);         \
      } while (0);
  
  int main(int argc, char *argv[])
  {
      int link[2];
      pid_t pid;
      char foo[4096];
  
      if (pipe(link) == -1)
          die(&quot;pipe&quot;);
  
      if ((pid = fork()) == -1)
          die(&quot;fork&quot;);
  
      if (pid == 0)
      {
  
          dup2(link[1], STDOUT_FILENO);
          close(link[0]);
          close(link[1]);
          execvp(&quot;./exec&quot;, argv);
          die(&quot;execl&quot;);
      }
      else
      {
  
          close(link[1]);
          int nbytes = read(link[0], foo, sizeof(foo));
          printf(&quot;Output: (%.*s)\n&quot;, nbytes, foo);
          wait(NULL);
      }
      return 0;
  }
  </code></pre>
  <p>exec.c</p>
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/shm.h&gt;
  
  int main(int argc, char *argv[])
  {
      char a;
      a='A';
      write(link[1],&amp;a,sizeof(a));
  
  
      return 0;
  }
  </code></pre>
  <p>I am just practicing and want to output the data that is save from pipe()</p>
  <p>What I am doing wrong, can you help me to debug?
  TIA!</p>