Delay function

Aug 9, 2008 at 4:15am
I'm looking for an equivalent function in Linux to the Sleep() function in Windows. That is, a function that holds execution for a certain amount of time without using CPU.
Also, is there any reference for Linux's system calls? Preferably in ebook form, but online works, too.
Aug 9, 2008 at 8:37am
closed account (z05DSL3A)
This may be what you are looking for:

Sleep service

The time period for the Win32 Sleep function is in milliseconds and can even be INFINITE, in which case the thread will never resume. The Linux sleep function is similar to Sleep, but the time periods are measured in seconds. To obtain the millisecond resolution, use the nanosleep function to provide the same service.

Win32 Sleep (50)

Equivalent Linux code
1
2
3
4
5
6
struct timespec timeOut,remains;

timeOut.tv_sec = 0;
timeOut.tv_nsec = 500000000; /* 50 milliseconds */

nanosleep(&timeOut, &remains);


HTH

Linux's system calls quick references:
http://www.digilife.be/quickreferences/QRC/LINUX%20System%20Call%20Quick%20Reference.pdf
Last edited on Aug 9, 2008 at 8:43am
Aug 9, 2008 at 11:53pm
Alright. Thanks!
Topic archived. No new replies allowed.