Reputation: 1061
Which clock is set by using stime() and clock_settime()? As I can read in man both can set a Linux time. Function stime() sets "the idea of time" and clock_settime() with parameter CLOCK_REALTIME can set a "system wide RTC".
1) What are these clocks?
2) Are there any differences?
3) Do they also set the HW clock?
4) If not: Does anybody know a smart way to set the hwclock in C/C++ without using ioctl()?
[Update 1]
More concrete point 4: What is the C equivalent for std::system("/sbin/hwclock -w")
?
Upvotes: 5
Views: 6591
Reputation: 1061
I answer my question with the help provided by MrSykkox.
I read http://linux.die.net/man/4/rtc and had a look into the given sources of sys-utils. Both show me that there are a lot of different HW-clocks types like CMOS, RTC, KD and so on. In a part of sys-utils code I found some descriptors are set by opening some specific devices like /dev/rtc, /dev/rtc0, /dev/misc/rtc, /dev/port exclusive for reading. And of course I found the ioctl() stuff for setting the RTC.
Conclusion
Upvotes: 1
Reputation: 528
Sorry for this short answer i actually just wanted to do a comment, but it wont allow me that.
Well to help you about your question 4. Some quick research on Google sent me to https://github.com/karelzak/util-linux/blob/master/sys-utils/hwclock.c I havent studied this code more than 2 minutes but a quick search showed line 468:
static void set_hardware_clock(const time_t newtime, const bool universal, const bool testing)
edit:
BTW Check out the wikipedia for it http://en.wikipedia.org/wiki/Util-linux and man rtc
Upvotes: 1
Reputation: 127
clock_settime()
and stime()
are the setter functions used for setting the system time and not the hardware clock which is independent of the Machine.
When a system boots, the system time is set with hardware clock.
Linux has a command for handling the hardware clock which is hwclock
. For more information check this link: http://linux.die.net/man/8/hwclock
Upvotes: 0