1

when i try to set the computer hardware clock like here descripted:

How Do You Programmatically Set the Hardware Clock on Linux?

its not working (the time is not updated to the new time).

fd = open("/dev/rtc", O_RDONLY); //<- return 3

ioctl(fd, RTC_SET_TIME, &rt); //<- return 0

When I add

system("/sbin/hwclock --systohc");

I get:

Cannot access the Hardware Clock via any known method

Executing hwclock --systohc from the terminal working.

It's a Ubuntu 10.10 mashine in VirtualBox.

I using Code::Blocks 10.05 with GCC 4.4.5

Here is my full source code:

http://pastebin.com/sgBBv1XA

And yes, I execute the programm as root.

Community
  • 1
  • 1
NKnusperer
  • 974
  • 1
  • 11
  • 31
  • Since you set time to rtc, not set by `stime`. `/sbin/hwclock --hctosys` should be called instead of `--systohc`. `--hctosys` would sync system time from hardware clock. – Louis Go Jan 14 '21 at 01:22

1 Answers1

1

I doubt, if it is possible to set HD clock in a machine running in virtual environemnt.

Unni
  • 1,721
  • 2
  • 14
  • 12