title: Calling ping using popen in C
body: <p>I have the following code in C code in CentOS linux. This code is called every 5 seconds in a thread. The code works fine if I disable pclose(fp), but I know I am supposed to do it. Can someone explain why it hangs at pclose(fp) when I enable it? 
  Many thanks. </p>
  
  <pre><code>FILE* fp;
  int status;
  char path[255];
  
  fp = popen("ping -c 3 -W 3 200.0.0.51", "r");
  sleep(3); 
  int i=0; 
  while (i &lt; 255) {
      path[i] = fgetc(fp); 
      i++;
  }
  
  char* str;
  str = strstr(path, "100% packet loss");
  
  if (str!=NULL) {
      //pclose(fp); // &lt;--- hangs here if I enable
      OS_Reboot(); 
  }
  </code></pre>