Home>Article> sleep() function introduction

sleep() function introduction

尚
Original
2019-07-23 15:54:13 7093browse

sleep() function introduction

#The Sleep function causes a computer program (process, task, or thread) to sleep, making it inactive for a period of time. When the timer set by the function expires, or a signal is received, or the program is interrupted, the program will continue to execute.

Usage:

The call to the sleep() function requires a time as a parameter, which represents the time interval for program execution to be suspended. Usually the parameter is in seconds, but in some more precise operating systems it can be in milliseconds or even microseconds.

Windows system

In the Windows operating system, the sleep() function requires a parameter in milliseconds to represent the program suspension time. The sleep() function is included in the kernel32.dll dynamic link library. , but there is no sleep() function that can be run directly in the batch file. The sleep() function can be found in Windows toolsets such as the Windows 2003 Resource Pack.

Unix system

In Unix-like operating systems, calling the sleep() function requires a parameter in seconds. If you need more precise time control, you can use the nanosleep() function.

C language example

In Windows system:

Sleep(2*1000); //sleep for 2 seconds

In Unix systems:

sleep(2); //sleep for 2 seconds

Example:

#include  #include int main() { int a; a=1000; printf("你"); Sleep(a);/* VC 使用Sleep*/ printf("好"); /*输出“你”和“好”之间会间隔一千毫秒,即间隔一秒,Sleep()的单位为毫秒*/ return 0; }

The above is the detailed content of sleep() function introduction. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:fat32 format Next article:fat32 format