C语言中的usleep函数用于暂停程序的执行一段时间,单位为微秒(1秒=1000000微秒)。
该函数的原型为:
```
int usleep(useconds_t microseconds);
```
参数`microseconds`表示要暂停的时间,类型为`useconds_t`,即无符号整型。
使用该函数需要包含头文件`
下面是一个使用usleep函数的示例:
```c
#include
#include
int main() {
printf("Start\n");
usleep(2000000); // 暂停2秒
printf("End\n");
return 0;
}
```
运行上述代码,输出结果为:
```
Start
(等待2秒)
End
```
在上述示例中,程序在执行到usleep函数时会暂停2秒,然后继续执行后面的代码。









