Function name: sleep
Header file: #include <windows.h>//use with top file in VC
#include <unistd.h>//The header file used in the GCC compiler differs depending on the GCC version
Function: Execution suspend specified number of seconds
Syntax: unsigned sleep (unsigned seconds);
#include <stdio.h> #include <stdlib.h> #include <time.h>int main () { int A; a=1; printf ("Hello"); Sleep (a); /* VC using sleep*/ printf ("World"); return 0;}
Function name: usleep
Header files: #include <unistd.h>
Function: Usleep function suspends the process for a period of time, in microseconds (one out of 10,000 seconds);
Syntax: void usleep (int micro_seconds);
return value: None
Description: This function temporarily causes the program to stop executing. The parameter micro_seconds is the number of microseconds (US) to pause.
Note
This function does not work in the Windows operating system. Used under the Linux test environment.
See also: Usleep () is similar to sleep () for delaying the suspend process. The process is suspended and placed into the Reday queue.
In general, use the sleep () function whenever possible with a delay of magnitude of seconds.
If the delay time is dozens of milliseconds (1ms = 1000us), or smaller, use the usleep () function whenever possible. This will make the best use of CPU time
The use and difference of sleep () and Usleep () under Linux