The use and difference of sleep () and Usleep () for Linux

Source: Internet
Author: User
Tags usleep

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

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.