Process Real-Time – How to Change Perception for One Process

processreal timetime

I would like to change the perception of real time for one process.

Making the process believe that time is passing at 50% or 150% of the speed my system/kernel/hardware-clock thinks.

I'd like to find a generic solution that can be used with any program, without having to patch the program's source code.

Is there any tool to achieve what I need?

Best Answer

That's what the faketime command is designed for. For instance:

$ time faketime -f '+0 x10' sh -c 'date +%T; sleep 10; date +%T'
13:29:02
13:29:12
faketime -f '+0 x10' sh -c 'date +%T; sleep 10; date +%T'  0.00s user 0.00s system 0% cpu 1.009 total

Started that shell with the clock going 10 times as fast as normal (that sleep 10 slept for 1 second).

Clock can be slowed down by using fractional multiplier (like 0.5 or 0,5 (depending on your locale) for every faked second to last 2 real seconds. See for instance:

faketime -f '+0 x0.5' watch date

That works by injecting code into executables with LD_PRELOAD, so won't work for statically linked applications or setuid/setgid executables, or applications that execute commands in sanitized environments or in user namespaces, or which obtain time information or sleep without using the libc system call wrappers.

Related Question