- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在填充 timespec 结构。目的是,用户将始终以秒为单位输入值(也可以是 0.01 秒),因此我们使用以下方法将秒转换为纳秒:lt_leak_start = atoll(getenv("LT_LEAK_START")) * sec_to_nsec;
其中变量 static long sec_to_nsec = 1000000000;
然后将其用作 settime 的参数:timer_settime(timerid,0,&its,NULL)
。但是这样做会发生错误:settimer failed: Invalid argument
请帮帮我。
提前致谢。
enter code here
struct timespec {
time_t tv_sec; /* Seconds */
long tv_nsec; /* Nanoseconds */
};
struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Initial expiration */
};
我正在尝试的代码在这里:
static long sec_to_nsec = 1000000000;
lt_leak_start = atoll(getenv("LT_LEAK_START")) * sec_to_nsec;
/* Setting timer interval */
its.it_interval.tv_sec=0;
its.it_interval.tv_nsec=1;
/* Setting timer expiration */
its.it_value.tv_sec=0; // First expiry after 1 sec
its.it_value.tv_nsec=lt_leak_start;
timer_create(CLOCK_REALTIME,&sevp,&timerid);
if(timer_settime(timerid,0,&its,NULL)==-1) {
perror("settimer failed");
exit(1);
}
最佳答案
double d = strtod(getenv("LT_LEAK_START"), 0);
...
its.it_value.tv_sec=(time_t) d;
its.it_value.tv_nsec=(d - (time_t) d) * sec_to_nsec;
将环境变量读取为 double 值。将第二部分存储在 tv_sec 中,将纳秒部分存储在 tv_nsec 中。
关于c - 秒到纳秒 - struct itimerspec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5457489/
我正在尝试使用timerfd_create() 和timer_settime() 用C 语言编写一个计时器。我正在使用 CLOCK_MONOTONIC。但是尽管我包含了这些头文件, #include
我有这个问题:我使用 itimerspec 结构创建了一个结构。 itimerspec 结构有两个字段: struct timespec { time_t tv_sec;
我正在填充 timespec 结构。目的是,用户将始终以秒为单位输入值(也可以是 0.01 秒),因此我们使用以下方法将秒转换为纳秒:lt_leak_start = atoll(getenv("LT_
几年前,我问了一个关于 how to initialize a timespec struct 的问题使用最少的代码行到归零状态(纳秒和秒等于零)。 许多回复告诉我不要使用 memset,因为这不是跨
我正在尝试将 POSIX 计时器与 POSIX 信号处理结合起来。当我尝试执行您可以在此处找到的代码时,我得到: timer_settime 错误:参数无效 在基于高级 Linux 编程和 Unix
因此,直到最近我们决定将其移至 Lubuntu 12.04 系统时,该代码才能正常运行。对 timer_settime 的调用返回 EINVAL,并在 gdb 下运行它我已经确认 ts 的所有字段在调
我是一名优秀的程序员,十分优秀!