2013-04-07 130 views
2

将时间写入RTC芯片/ dev/rtc上的ioctl RTC_SET_TIME可用于设置RTC芯片的时间和日期。但是/ dev/rtc只允许一个进程打开它。是否可以使用clock_settime()

所以我打算继续使用clock_settime()这不需要打开/ 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. 
+2

不,这个功能不是用来设置任何(硬件)*时钟*。它旨在用于用户空间程序测量*时间*。如果你想要一个时钟(“挂钟”)安装NTP,它将处理系统中的实际时间。 – wildplasser 2013-04-07 10:53:17

回答

0

不幸的是,不,clock_settime()不更新实时时钟(RTC)。

我看到人们在调用clock_settime()来强制RTC更新后使用system("rtc -s hw");