LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-15-2005, 10:05 AM   #1
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Rep: Reputation: 30
linux sleep()


I heard that the linux sleep() function works with seconds. If so what function sleeps for milliseconds? And what header do i need to have to be able to call sleep() in linux? Thanks.
 
Old 01-15-2005, 10:39 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
man usleep

That works on a microsecond level.
 
Old 01-15-2005, 10:45 AM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 11
Posts: 8,052

Rep: Reputation: 456Reputation: 456Reputation: 456Reputation: 456Reputation: 456
"what function sleeps for milliseconds? "

nanosleep works in nanoseconds.

"what header do i need to have to be able to call sleep() in linux?"

I think that both nanosleep and sleep are part of stdlib.h.


-------------------------
Steve Stites
 
Old 01-15-2005, 11:14 AM   #4
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Original Poster
Rep: Reputation: 30
thanks, i already got both to work, really stupid mistake did Sleep instead of sleep, but now i have it all working. Thanks though, sorta annoying there is no millisecond one, because the microsecond sleep will probably be less acurate, but since i don't really need too much precision, it's all good. Thanks.
 
Old 01-15-2005, 12:42 PM   #5
Nerox
Member
 
Registered: Jul 2004
Location: Spain
Posts: 111

Rep: Reputation: 20
Since a millisecond = 10^3 microseconds you can do the following:
Code:
void millisleep(int milliseconds)
{
      usleep(milliseconds * 1000);
}

Last edited by Nerox; 01-15-2005 at 12:44 PM.
 
Old 01-15-2005, 12:48 PM   #6
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Original Poster
Rep: Reputation: 30
Did that already :P . Just was saying that if the usleep timer is off by 0.01 usec a beat that means it will be off by 0.01 ms a beat, and if you need precision (like a millisecond timer), it isn't good. Bah, it's not important :P.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Searching for Server (BOOTP/DHCP) <sleep> <sleep> .. .. Eileen Linux - Networking 12 10-21-2005 01:14 AM
Linux Sleep Mode? RynoFly Linux - Newbie 1 01-17-2005 01:21 AM
Linux Won't Recover after Sleep lramos85 Linux - Laptop and Netbook 0 05-15-2004 12:23 AM
How do sleep under 20 ms in Linux? vedion Linux - Software 1 04-23-2004 06:03 AM
Linux C : A better way to sleep/timer? jimmy416 Programming 8 10-14-2003 12:58 PM

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

All times are GMT -5. The time now is 02:44 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