LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2004, 04:19 AM   #1
ujnam
LQ Newbie
 
Registered: Oct 2004
Distribution: RedHat
Posts: 3

Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I read disc and space used information on a DVD? opera_sys Linux - Hardware 2 07-19-2004 05:17 PM
How do I read disc and space used information on a DVD? opera_sys Linux - Hardware 1 07-19-2004 11:28 AM
Read the output from a pipe with bash ? fluppi Linux - Software 3 01-13-2004 12:59 PM
Time and Version Information jc2it Slackware 13 01-08-2004 11:16 AM
read and pipe function dummyagain Programming 13 09-24-2003 10:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration