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
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:

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

Sleep (1); Stay for 1 seconds.
Delay (100); Stay for 100 milliseconds
Sleep (100); Stay for 100 milliseconds
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);
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.