Linux Sleep command parameters and usage--linux hibernate delay execution Command __linux

Source: Internet
Author: User
Tags function prototype linux sleep sleep function usleep
Use Rights: All users
Use mode: Sleep [--help] [--version] NUMBER[SMHD]
Description: Sleep can be used to delay the current action for a period of time
Parameter description:
--HELP: Display auxiliary messages
--version: Display version number
Number: Length of time, followed by S, M, H or D
Where S is the second, M is minutes, H is the hour, D is the number of days
Example:
Delay 1 minutes after displaying the current time, and then display the time again:
Date;sleep 1m;date


This command is more used in shell scripting and in programs.


As in the following procedure:

Application:
#include <syswait.h>
Usleep (n)//n microsecond
Sleep (n)//n ms
Sleep (n)//n seconds
Driver:
#include <linux/delay.h>
Mdelay (n)//milliseconds its implementation
#ifdef NOTDEF
#define MDELAY (n) (\
{unsigned long msec= (n); while (msec--) udelay (1000);})
#else
#define MDELAY (n) (\
(__builtin_constant_p (n) && (n) <=max_udelay_ms)? Udelay ((n) *1000): \
({unsigned long msec= (n); while (msec--) udelay (1000);}))
#endif
Call Asm/delay.h's udelay,udelay should be nanosecond delay


Dos:
Sleep (1); Stay for 1 seconds.
Delay (100); Stay for 100 milliseconds
Windows:
Sleep (100); Stay for 100 milliseconds
Linux:
Sleep (1); Stay for 1 seconds.
Usleep (1000); Stay for 1 milliseconds
Each platform is not the same, it is best to define a Cross-platform macro control


Seconds or microseconds. About the delay function sleep ()
Because to write a piece of code, you need to use the sleep () function, in my memory (10) seems to be dormant 10 microseconds, the result is dormant for 10 seconds (under Linux). I think it's strange, because the chief remembers it as if it was a microsecond unit. So I looked it up.

The original Sleep function prototype under Linux is:
unsigned int sleep (unsigned int seconds);
And the Sleep function prototype in MFC is:
void Sleep (DWORD dwmilliseconds);
That is, under Linux (the GCC library used), The sleep () function is in seconds, sleeping (1), or dormant for 1 seconds. The sleep () function under MFC is in microseconds (1000) and sleeps for 1 seconds. Oh, yes. And if you sleep in subtle units under Linux, you can use the thread-hibernate function: void Usleep (unsigned long usec); Don't forget to use #include <system.h> oh.

Also worth mentioning is that Linux has a delay () function, the prototype is extern void delay (unsigned int msec), it can delay msec*4 milliseconds, that is, if you want to delay a second, you can use delay (250);

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.