Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug, Unix. Run a program with a different time from the system

Tags:

unix

I am debugging a program in MacOSX, and I need that this program thinks we are one year later than the one given by the operating system.

I cannot change the time of the operation system, because I need to run a second program concurrently with the correct time. I could modify the code of the first program to add one year each time it gets the time from the operation system, but the code is too big to do that; I prefer not to use this solution.

I heard once that there is a command in Unix to run a program with a fake/mocked time. Do you know about it?

like image 481
David Portabella Avatar asked Oct 20 '11 12:10

David Portabella


People also ask

How do I run a Unix command in debug mode?

The most common is to start up the subshell with the -x option, which will run the entire script in debug mode. Traces of each command plus its arguments are printed to standard output after the commands have been expanded but before they are executed. This is the commented-script1.sh script ran in debug mode.

How do I run a program in debug mode?

To run a program in a debuggerClick the Image File tab. In the Image box, type the name of an executable file or DLL, including the file name extension,and then press the TAB key. This activates the check boxes on the Image File tab. Click the Debugger check box to select it.


1 Answers

I haven't tried it, but libfaketime claims to do what you need.

Quoted from the website:

As an example, we want the "date" command to report our faked time. To do so, 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 the lib works as advertised, you can trick your program into thinking it was running a year ahead using:

LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="+1y" ./your_program
like image 56
Shawn Chin Avatar answered Sep 21 '22 20:09

Shawn Chin