Function: Execution hangs for a period of time
Usage: unsigned sleep (unsigned seconds);
Attention:
Used in VC with top file # # <WINDOWS.H> under Linux, the GCC compiler uses a header file that differs depending on the GCC version # include <unistd.h>
In the VC, sleep in the first English characters in uppercase "S", in Linux do not capitalize, in the standard C is sleep, do not capitalize, simply say VC with sleep, all other uses sleep
In the VC, the Unit in Sleep () is in milliseconds, so if you want the function to be stuck for 1 seconds, it should be sleep (1000); Under Linux, the units in sleep () are seconds, not milliseconds.
Example:
#include <stdio.h> #include <windows.h>int main () { int a=100; Sleep (3000);//stall 3s print a printf ("%d", a); return 0;}
Usleep function:
Function: The Usleep function suspends the process for a period of time, in microseconds us (one out of 10,000 seconds).
Syntax: void usleep (int micro_seconds);
return value: None
Note: This function does not work in the Windows operating system.
Usleep () is similar to sleep () for delaying the suspend process. The process is suspended and placed into the Reday queue. Just in general, use the sleep () function whenever possible with a delay of magnitude of seconds. And this function has been revoked, you can use Nanosleep.
If the delay time is dozens of milliseconds, or smaller, use the usleep () function whenever possible. This will make the best use of CPU time.
Delay function:
Function: Pause the execution of a program for a period of milliseconds MS (1 per thousand seconds)
Usage: void delay (unsigned milliseconds);
Example:
#include <dos.h> int main (void) {Sound (440); Delay (500); Nosound (); return 0; }
Delay () is a cyclic wait, and the process is still running, consuming the processor.
Sleep () is different, it is suspended, and the processor is ceded to other processes.
Sleep function of C language