Temporarily change time

There's a library called libfaketime (also on GitHub) which allows you to make the system report a given time to your application. You can either have the system report a fixed time for the duration of the program execution, or start the clock at some specific time (for example, 01:59:30). Basically, you hook the faketime library into your program's in-memory image through the library loader, and it captures and handles in its own way all system calls which relate to system time. It doesn't exactly change the system time, but it changes what time is reported to your specific application without affecting anything else that is running, which is probably what you really are after (otherwise, I see no reason to not just change the global system time).

There's a number of possible variants on how to use it, but it looks like Changing what time a process thinks it is with libfaketime has a pretty thorough listing along with sample code to try them out. Google should also be able to unearth some examples given that you know what to search for.

It would appear that it isn't available prepackaged through the RHEL repositories, but for example Debian provides it under the package name faketime. It also looks straight forward to build from source code (it apparently doesn't even need a configure step or anything like that).


What I would do is first install an ntp service to synchronize time with a remote server. Then, stop the service, manually change the date, play around and restart the service:

service ntpd stop
date -s "Aug 11 2012"
[ do stuff ]
service ntpd start

Tags:

Linux

Time

Rhel