LoginSignup
10
9

More than 5 years have passed since last update.

nohup コマンド

Posted at

nohup

この記事は Linux コマンド 全部オレ Advent Calendar 2017 の14日目の記事です。

NAME
     nohup -- invoke a utility immune to hangups

SYNOPSIS
     nohup [--] utility [arguments]

DESCRIPTION
     The nohup utility invokes utility with its arguments and at this time sets the signal
     SIGHUP to be ignored.  If the standard output is a terminal, the standard output is
     appended to the file nohup.out in the current directory.  If standard error is a ter-
     minal, it is directed to the same place as the standard output.

     Some shells may provide a builtin nohup command which is similar or identical to this
     utility.  Consult the builtin(1) manual page.

意味としては HUP シグナルを無視したいときに使う。

よく使いそうな使い方

nohup コマンド & で、コマンドを実行し仮想端末を閉じたりログアウトしてもコマンドが動き続けるようにする。
一般的には仮想端末を閉じると、HUP シグナルが送られてそのプロセスは終了する(※)が、それを無視することでプロセスを動かせ続けるようにする。

[sinsengumi ~]$ nohup sleep 30 &

nohup つけなくても動き続けてるけど?

bash だと huponexit がデフォルト OFF になっているから。これが OFF だと exit しても SIGHUP は送られない。

参考

nohup とデーモンの違い

デーモンのざっくりした定義としては以下らしい。

  1. バックグランドで動作している
  2. 制御端末を持たない
  3. 他のプロセスグループに属さない
  4. 親プロセスが init

3, 4 あたり満たしてないので、デーモンとは言わない感じ。
systemd や supervisord などでサービス化されてるものはデーモンと呼んで良さそう。

参考

10
9
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
10
9