Debugging, Unix. Starting a program at another time from the system

I am debugging a program on MacOSX, and I need this program to think that we are one year later than the operating system.

I can’t change the operating time of the operating system because I need to run the second program at the same time as the right one. I could change the code of the first program to add one year every time it receives time from the operating system, but the code is too large to do so; I prefer not to use this solution.

I once heard that on Unix there is a command to run a program with fake / ridiculed time. Do you know about this?

+6
source share
1 answer

I have not tried, but libfaketime claims to do what you need.

Quote from the website:

As an example, we want the date command to report our fake time. To do this, we could use the following command line:

user@host > date Tue Nov 23 12:01:05 CEST 2007 user@host > LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d" date Mon Nov 8 12:01:12 CEST 2007 

Assuming lib works as advertised, you can trick your program into thinking it works a year in advance using:

 LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="+1y" ./your_program 
+4
source

Source: https://habr.com/ru/post/899696/


All Articles