title: How to use pipes in C?
body: <p>I tried to write a code where a variable should be updated in shared memory. So, I used fork() to create child process. The problem that I have is that I don't know how to use pipes, so that when some value has been reached and one process determines that, it should tell the other process that the output is finished, by using pipe. I was looking at lot of examples where pipes have been used, but still I am not sure how to implement that. If anyone could help me with some guidelines how to do this, I would be really thankful. 
  Here is the code:</p>
  
  <pre><code>`#include &lt;stdio.h&gt;
   #include &lt;stdlib.h&gt;
   #include &lt;unistd.h&gt;
   #include &lt;semaphore.h&gt;
   #include &lt;sys/mman.h&gt;
   #include &lt;sys/types.h&gt;
   #include &lt;sys/wait.h&gt;
  
      int main(void)
  {
  int * shared=mmap(NULL, sizeof(int), PROT_READ|PROT_WRITE,MAP_SHARED|MAP_ANONYMOUS, -1, 0);
   printf("Value of the variable at the beginning: %d\n", * shared);
  pid_t pid;
  pid=fork();
  
  if(pid==0)
  {
  int a=0;
  a=* shared;
  a+=3;
   printf("Child process: %d\n", a);
  sleep(rand()%10);
  }
     else{
   int b=0;
  b= * shared;
  b+=2;  
   printf("Parent process: %d\n", b);
  sleep(rand()%10);
       } 
     }
  </code></pre>