I don't know exactly how to word a search for this.. so I haven't had any luck finding anything.. :S
I need to implement a time delay in C.
for example I want to do some stuff, then wait say 1 minute, then continue on doing stuff.
Did that make sense? Can anyone help me out?
Is it
timer
?For WIN32 try http://msdn.microsoft.com/en-us/library/ms687012%28VS.85%29.aspx
Check sleep(3) man page or MSDN for Sleep
you can simply call delay() function. So if you want to delay the process in 3 seconds, call delay(3000)...
There are no
sleep()
functions in the C Standard Library, but POSIX does provide a few options.The POSIX function
sleep()
(unistd.h) takes anunsigned int
argument for the number of seconds desired to sleep. Although this is not a Standard Library function, it is widely available, and glibc appears to support it even when compiling with stricter settings like--std=c11
.The POSIX function
nanosleep()
(time.h) takes two pointers totimespec
structures as arguments, and provides finer control over the sleep duration. The first argument specifies the delay duration. If the second argument is not a null pointer, it holds the time remaining if the call is interrupted by a signal handler.Programs that use the
nanosleep()
function may need to include a feature test macro in order to compile. The following code sample will not compile on my linux system without a feature test macro when I use a typical compiler invocation ofgcc -std=c11 -Wall -Wextra -Wpedantic
.POSIX once had a
usleep()
function (unistd.h) that took auseconds_t
argument to specify sleep duration in microseconds. This function also required a feature test macro when used with strict compiler settings. Alas,usleep()
was made obsolete with POSIX.1-2001 and should no longer be used. It is recommended thatnanosleep()
be used now instead ofusleep()
.Write this code :