Help regarding popen() and pclose()
hi folks,
iam a newbie to linux environment iam using popen() to run script(s) in thread(s)
all i need is my scripts should execute in parallel without starving for cpu and log the results(of scripts) in to log.
here i cannt use pclose because it will close process as well as pipe opened by popen (), i need to use this pipe for logging later.
so i did following code change in my code to acheive popen(),pclose() functionality.
is there any pitfaults/leaks with my code if so please let me know.
int main ()
{
FILE *Fp = NULL;
char buf[128]={0};
int pid;
int status;
Fp = popen("./myscript.sh", "r");
fgets(buf,128,Fp);
pid=atoi(buf);
if ( waitpid((pid_t)pid,&status,0) <0)
{
printf("wait failed:\n");
}
fclose(Fp);
return 0;
}
it is working fine but i need to know above code effects in complete process(i mean run time errors).
thx in adv
~shankar
|