Home > Common Problem > body text

sleep() function introduction

Release: 2019-07-23 15:54:13
Original
7174 people have browsed it

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 <windows.h>
#include<stdio.h>
int main()
{
int a;
a=1000;
printf("你");
Sleep(a);/* VC 使用Sleep*/
printf("好"); /*输出“你”和“好”之间会间隔一千毫秒,即间隔一秒,Sleep()的单位为毫秒*/
return 0;
}
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template