The use and distinction of the Linux Sleep () and usleep () __linux

Source: Internet
Author: User
Tags linux sleep usleep
Function Name: Sleep
Header file: #include <windows.h>//use with top files in VC
#include <unistd.h>//In the GCC compiler, the header file used differs depending on the version of GCC
Function: Execution suspend specified number of seconds
Grammar: 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 to suspend the process for a period of time, the Unit is microsecond (one out of 10,000 seconds);
Syntax: void usleep (int micro_seconds);
return value: None
Content Description: This function can temporarily stop the execution of the program. The parameter micro_seconds is the number of microseconds (US) to pause.
Attention
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 a pending process. The process is suspended and placed in the Reday queue.
In general, the Sleep () function is used whenever possible when the order of magnitude of delay is 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 minus 6 second square seconds)
0.000 001 microseconds = 1 picosecond
0.001 microseconds = 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 ms (ms) = 1,000,000 microseconds (μs) = 1,000,000,000 nanoseconds (ns) = 1,000,000,000,000 picosecond (PS)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.