- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
下面的tim.tv_sec
和tim.tv_nsec
有什么用?
如何让执行休眠 500000
微秒?
#include <stdio.h>
#include <time.h>
int main()
{
struct timespec tim, tim2;
tim.tv_sec = 1;
tim.tv_nsec = 500;
if(nanosleep(&tim , &tim2) < 0 )
{
printf("Nano sleep system call failed \n");
return -1;
}
printf("Nano sleep successfull \n");
return 0;
}
最佳答案
半秒是 500,000,000 纳秒,因此您的代码应为:
tim.tv_sec = 0;
tim.tv_nsec = 500000000L;
就目前而言,您的代码休眠了 1.0000005 秒(1 秒 + 500 纳秒)。
关于c - 如何在 C 中使用 nanosleep()?什么是 `tim.tv_sec` 和 `tim.tv_nsec` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7684359/
我正在尝试运行以下代码(一个简单的备份程序),但由于某种原因,无法解析字段 tv_sec 。我尝试了我想到的一切 - 但没有帮助。我想强调的是,我已阅读本网站中的其他相关问题,并尝试添加以下行: #i
我有一个应用程序调用gettimeofday来存储该部分代码开始运行的tv_sec。这段代码非常简单: struct timeval tvnow; gettimeofday(&tvnow); int
我只是在学习如何使用 clock_getres(网络上几乎没有任何关于此的好文档)。我的代码如下所示: timespec now; clock_getres(CLOCK_REALTIME,&now);
手册页 getitimer(2) 声称 both tv_sec and tv_usec significant in determining the duration of a timer 它没有继续
我正在尝试获取上次修改文件的时间,但出现未找到字段的错误。 use std::{fs, io, time}; fn main() -> io::Result { let metadata =
对于以下代码,getrusage 在 ru_utime.tv_usec 和 ru_utime.tv_sec 中返回零。 代码: #include "stdlib.h" #include "stdio.
下面的tim.tv_sec和tim.tv_nsec有什么用? 如何让执行休眠 500000 微秒? #include #include int main() { struct timespe
我是一名优秀的程序员,十分优秀!