/*********************************************************************************
|
* Copyright: (C) 2025 LingYun IoT System Studio
|
* All rights reserved.
|
*
|
* Filename: sleep.c
|
* Description: This file is sleep example code.
|
*
|
* Version: 1.0.0(10/15/2025)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "10/15/2025 05:16:02 PM"
|
*
|
********************************************************************************/
|
|
#include <stdio.h>
|
#include <time.h>
|
#include <unistd.h>
|
|
int main(void)
|
{
|
struct timespec req;
|
|
printf("Sleep 2 seconds using sleep()\n");
|
sleep(2);
|
|
printf("Sleep 0.5 seconds using nanosleep()\n");
|
req.tv_sec = 0;
|
req.tv_nsec = 500000000; /* 0.5 秒 */
|
nanosleep(&req, NULL);
|
|
printf("Sleep 0.1 seconds using clock_nanosleep()\n");
|
req.tv_sec = 0;
|
req.tv_nsec = 100000000; /* 0.1 秒 */
|
clock_nanosleep(CLOCK_MONOTONIC, 0, &req, NULL);
|
|
return 0;
|
}
|