title: pppd popen hanging in C
body: <p>I am launching pppd using popen in my program to make obtaining the IP address and interface name a little bit easier. My code runs fine independently and is a pretty typical implementation. The problem begins when it runs in the full program (too large to post)... the loop seems to hang for quite a while at the fgets() line. The popen is launched in its own thread that is then managed based on the output. </p>
  
  <p>The popen/pppd code is essentially the following.</p>
  
  <pre><code>int main(void){
      pthread_create(&amp;thread, NULL, pppd, (char *)NULL);
      pthread_join(thread, NULL);
  
      return 0;
  }
  
  void *pppd(char *args){
      char* command = malloc(32);
  
      sprintf(command, "pppd %s call %s", dev, provider);
      pppd_stream = popen(command, "r");
  
      if(pppd_stream == NULL){
          pppd_terminated = TRUE;
          return;
      }
  
      free(command);
  
      while(fgets(buffer, 128, d-&gt;pppd_stream) != NULL){
  
          //handle_output
      }
  
  }
  </code></pre>
  
  <p>CPU usage isnt a problem, the system and the other parts of the program are still responsive and running as expected.</p>
  
  <p>Any thoughts on what could be causing this slow down?</p>