title: How to add a third child process?
body: <p>There is a code with two process. Also need to add  a third proccess. Processes communicate &quot;Hello, world&quot; to each other. Hello, world -&gt; (Hello, world) -&gt; {(Hello, world)}</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/wait.h&gt;
   
  int main() {
    int ps[2];
    int pid[2];
    if(pipe(ps)!=0) {
      printf(&quot;pipe error\n&quot;);
      return 1;
    }
   
    if((pid[0]=fork())==0) { //first process
      close(ps[0]);
      dup2(ps[1],1);
      close(ps[1]);
      puts(&quot;Hello, World&quot;);
      exit(0);
    }
  if((pid[1]=fork())==0) { //second process
      int i;
      char bf[120]=&quot;&quot;;
      close(ps[1]);
      dup2(ps[0],0);
      close(ps[0]);
      for(i=0;(bf[i]=getchar())!=EOF;i++);
      bf[i-1]='\0';
      printf(&quot;from %d: read %d '%i'\n&quot;,getpid(),strlen(bf),bf);
      exit(0);
    }
   
    close(ps[0]);
    close(ps[1]);
    waitpid(pid[0],NULL,0);
    waitpid(pid[1],NULL,0);
    return 0;
  }
  </code></pre>