LinuxQuestions.org
Visit Jeremy's Blog.
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 02-09-2004, 09:57 AM   #1
frostmagic
LQ Newbie
 
Registered: Sep 2003
Posts: 28

Rep: Reputation: 15
select function as timeout?


struct timeval start,cur,timeout;

long duration;

timeout.tv_sec=0;
timeout.tv_usec = 555;

gettimeofday(&start,NULL);
select(0,NULL,NULL,NULL,&timeout);
gettimeofday(&cur,NULL);

duration = (cur.tv_sec-start.tv_sec)*1000000;
duration = duration + cur.tv_usec - start.tv_usec;

printf("%ld\n", duration);

Dont seems to get the correct time everytime i run it.
Run it ten time, only 2 times the value were near 555. Other 8 times were either too short or too long.

Anyone has any idea about this?
 
Old 02-09-2004, 11:18 AM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
for one you havent checked for overflow of the usecs
 
Old 02-09-2004, 11:56 AM   #3
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Also, Linux is not a real-time OS (RTLinux is), so you aren't guaranteed any sort of granularity in your response time. It will get it as close as it can, but that's not guaranteed to be as close as you want. If you want something with microsecond resolution, use a real-time OS.
 
  


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
perl: can I make the system function timeout? apeekaboo Programming 7 07-24-2007 07:52 AM
PHP: html Form Select function problem camlinux Programming 2 05-15-2005 08:23 PM
Select() did not select my socket thvo Programming 1 05-08-2005 12:20 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
Bash Select Function: Formatting Output mooreted Linux - General 2 03-28-2004 06:26 AM

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

All times are GMT -5. The time now is 04:25 AM.

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