1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

実際にプロセスを起動せずに、あたかも起動しているように偽装する方法

Last updated at Posted at 2017-09-29

やりたいこと

あるバッチ処理で、hulftのデーモンが起動しているか確認する処理があった。
このバッチを正常終了させたいが、実際にhulftのデーモンを起動させることはできない。
(ローカル環境でhulftコマンドがなかったり、デーモンを起動させるとなにかとよろしくないような場合)

hulftのデーモンはhulobsd、hulsndd、hulrcvdの3種類あり、これらが起動している状態に偽装する。
つまり、pgrep -c hulの結果を3にしたい。

やり方

1.sleepコマンドをコピーする
※「~」はホームディレクトリと呼ばれる場所です。

cp -p $(which sleep) ~/bin/hulobsdSleep
cp -p $(which sleep) ~/bin/hulsnddSleep
cp -p $(which sleep) ~/bin/hulrcvdSleep

2.コマンドを配置したディレクトリへパスを通す(通っていれば不要)

PATH=~/bin:${PATH}

3.sleepをバックグラウンドで起動する
1hは1時間という意味。ここはなんでもよい。
指定なしでもいいかと思ったけど、killし忘れると面倒なことになる。

hulobsdSleep 1h &
hulrcvdSleep 1h &
hulsnddSleep 1h &

4.プロセスが起動したか確認する(任意)

$ ps | grep Sleep
10658 pts/0    00:00:00 hulobsdSleep
10660 pts/0    00:00:00 hulrcvdSleep
10662 pts/0    00:00:00 hulsnddSleep

5.バッチ処理を実行する

6.プロセスを停止する

pkill Sleep

7.プロセスが停止したか確認する(任意)
何も出力されなければOK。

ps | grep Sleep

以上

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?