time taken to read the information present in pipe
gettimeofday(&tv1,&tz);
if( (fp = popen("df -m .","r")) == NULL)
{
printf("Not able to execute the command 'df -m'\n");
return 2;
}
memset(&tv2,0,sizeof(tv2));
memset(&tz,0,sizeof(tz));
gettimeofday(&tv2,&tz);
printf("the time taken to execute df command is %ld - %ld = %ld\n", tv2.tv_usec, tv1.tv_usec,(tv2.tv_usec - tv1.tv_usec));
/* reading the output of the 'df -m' from the pipe */
memset(&tv1,0,sizeof(tv1));
memset(&tv2,0,sizeof(tv2));
memset(&tz,0,sizeof(tz));
gettimeofday(&tv1,&tz);
fgets(buf,sizeof(buf),fp);
memset(buf,0,sizeof(buf));
fgets(buf,sizeof(buf),fp);
memset(&tz,0,sizeof(tz));
gettimeofday(&tv2,&tz);
printf("time taken to read the information from the pipe written by popen is %ld - %ld = %ld\n",tv2.tv_usec,tv1.tv_usec,(tv2.tv_usec - tv1.tv_usec));
pclose(fp);
When the above snippet of code is embedded in one of the server coding, we get the time taken to read the information from pipe is around 9000 micro seconds, but when i run same snippet of code as a simple program, i get the time taken to read the information from the pipe about 50-60 micro seconds, can i know what might be the reason?
Last edited by ujnam; 10-27-2004 at 04:20 AM.
|