可以使用/dev/rtc上的ioctl 时间为RTC芯片设置时间和日期。但是/dev/rtc只允许一个进程打开它。
因此,我计划继续使用定时(),它不需要打开/dev/rtc设备。但我不清楚它是否将日期和时间设置为RTC芯片。
根据手册页,clock_settime() API支持时钟跟踪。哪一个写入RTC芯片(如果它支持)?
CLOCK_REALTIME
System-wide realtime clock. Setting this clock requires appropriate privileges.
CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since some unspecified starting point.
CLOCK_PROCESS_CPUTIME_ID
High-resolution per-process timer from the CPU.
CLOCK_THREAD_CPUTIME_ID
Thread-specific CPU-time clock. 发布于 2013-12-06 21:03:36
不幸的是,没有,clock_settime()没有更新实时时钟。
我见过人们在调用system("rtc -s hw");以强制进行RTC更新之后使用clock_settime()。
发布于 2020-10-08 10:09:33
简短回答:
是否clock_settime()写入RTC是未指定的,因此实现特定的。
长答案:
调用clock_settime(CLOCK_REALTIME,.)保证设置操作系统的系统时钟,这是内核中的一个软件时钟。没别的了。
底线:在设置RTC之前,了解一下在您的平台上是如何实现的。
https://stackoverflow.com/questions/15860421
复制相似问题