title: How to using pipe in loop, is mine correct?
body: <p>I want to know if my usage of pipe is correct, this code is in the fork() child process, and pfd is pipe pointer:</p>
  
  <pre><code>char buf[1024];
  while(1){
      signal(SIGUSR1, OnSigUsr1);
      sleep(10000);
      if(get==1){
          get=0;
          close(pfd[1]);
          read(pfd[0], buf, sizeof(buf));
          close(pfd[0]);
      }
  }
  </code></pre>
  
  <p>another episode of code in the parent code:</p>
  
  <pre><code>char buffer[1024];
  /*put something in buffer*/
  close(pfd[0]);
  if(write(pfd[1], buffer, strlen(buffer))==-1){
       printf("error write\n");
  };
  close(pfd[1]);
  kill(fpid,SIGUSR1);
  </code></pre>
  
  <p>My problem is the buffer can be written and get from fork() for only one time, next time it can't be written in pipe again and return <code>error write</code>. I wonder if I made it some place wrong. Thanks.</p>