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.
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 < 255) {
path[i] = fgetc(fp);
i++;
}
char* str;
str = strstr(path, "100% packet loss");
if (str!=NULL) {
//pclose(fp); // <--- hangs here if I enable
OS_Reboot();
}