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.
The popen/pppd code is essentially the following.
int main(void){
pthread_create(&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->pppd_stream) != NULL){
//handle_output
}
}
CPU usage isnt a problem, the system and the other parts of the program are still responsive and running as expected.
Any thoughts on what could be causing this slow down?