2024年4月26日发(作者:)

在Linux的C语言中,`sleep()`函数用于使程序挂起一段时间。

该函数的原型定义在头文件`unistd.h`中。

以下是`sleep()`函数的原型:

```c

unsigned int sleep(unsigned int seconds);

```

参数`seconds`指定了程序需要挂起的时间,以秒为单位。函数返

回值为0,表示成功挂起指定的时间。

以下是一个使用`sleep()`函数的示例程序:

```c

#include

#include

int main() {

printf("开始休眠n");

sleep(5); // 休眠5秒钟

printf("休眠结束n");

return 0;

}

```

该程序首先输出一条消息"开始休眠",然后调用`sleep(5)`函数使

程序挂起5秒钟,最后输出一条消息"休眠结束"。