Hi,
I am having a hell of a time getting this to work. So basically, I have opened a popen to run a program that is going to prompt an action to occur half way through, when it gets to this I need to create a separate process and do some stuff, then return to the original process. This works fine until I re-enter the parent process then I get "glibc detected *** double free or corruption.
Here is the skeleton code:
int main (void)
{
pid_t pid1;
FILE *fp;
int i,index;
index = 0;
fp = popen("myprogram","r");
while(!feof(fp))
{
fscanf(fp,"%s",&stuff);
if( !strcmp(stuff,"point"))
{
rv = getrv();
fprintf(stdout,"%2.2f%%\n",result);
}
if (rv == 0 && index == 0)
{
index = 1;
pclose(fp2);
pid1 = fork();
if (pid1 == 0)
{
printf("some txt stuff\n");
_exit(0);
}
else{
wait();
}
}
}
pclose(fp);
system("rm return.txt");
return 0;
}
I have been working on this error of most of a day now. Anybody have any theories?
Thankz
---------- Post updated at 10:45 PM ---------- Previous update was at 10:24 PM ----------
Actually I figured it out. I was closing fp2 twice. Now it works fine