LoginSignup
24
24

More than 5 years have passed since last update.

Linuxプロセスに、偽のシステム時間を使わせる

Last updated at Posted at 2016-02-25

問題

(テストのために)Linuxプロセスに偽のシステム時間を使わせたい。

解決

libfaketimeを使って、時間関係のシステムコールをハイジャックする。

ビルド

$ git clone https://github.com/wolfcw/libfaketime && cd libfaketime && make

$ find "$PWD" -name libfaketime.so.1
/XXX/YYY/libfaketime/src/libfaketime.so.1                        # ライブラリファイルの絶対パス

使用

※ここで例としてrails sを実行する

$ LD_PRELOAD=/XXX/YYY/libfaketime/src/libfaketime.so.1 FAKETIME="+0d" rails s
                                                       ^ # オフセット=0 (現在)
....
[2016-02-24 07:01:41] INFO  WEBrick 1.3.1
(Ctrl-C)

$ LD_PRELOAD=/XXX/YYY/libfaketime/src/libfaketime.so.1 FAKETIME="+30d" rails s
                                                       ^ # オフセット=30日後
...
[2016-03-25 07:02:08] INFO  WEBrick 1.3.1

オフセット以外の方法で偽時間を指定する

オフセット(+30d)以外も指定方法があります、詳細はホームページに。

24
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
24