The use and difference of sleep () and Usleep () for Linux
[Date: 2013-03-23] |
Source: Linux Community Fireroll |
[Font: Big Small] |
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);
Example:
#include <windows.h>
#include <stdio.h>
int main ()
{
int A;
A=1;
printf ("Hello");
Sleep (a); /* VC Use 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.
It is normal to 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
Clock conversion:
microsecond, time unit, symbol US (English: microsecond).
1 microseconds equals one out of 10,000 seconds (10 of negative 6 second)
0.000 001 μs = 1 Leather seconds
0.001 μs = 1 nanoseconds
1,000 microseconds = 1 milliseconds
1,000,000 microseconds = 1 seconds
1s = 1000ms
1ms = 1000μs
1μs = 1000ns
1ns = 1000ps
1 seconds (s) = 1000 milliseconds (ms) = 1,000,000 microseconds (μs) = 1,000,000,000 nanoseconds (ns) = 1,000,000,000,000 picosecond (PS)
The use and difference of sleep () and Usleep () for Linux