nohup

プロセスとシステム

書き方

nohup <command> [args] &

HUP シグナルを無視させて、ログアウト後もコマンドが生き続けるようにします。バックグラウンドには回してくれないので `&` は自分で付け、出力は静かに ./nohup.out にたまります。

よく使うオプション

オプション意味
&You add this yourself: nohup alone does not put the command in the background.
> out.log 2>&1Send output somewhere other than the default ./nohup.out.
< /dev/nullDetach stdin as well, so the command cannot stall waiting for input.

nohup ./server.sh > server.log 2>&1 &

Start the server so it survives logout, with its own log file.

nohup make -j4 &

Run a long build that keeps going after you disconnect; output lands in nohup.out.

何が動いていて何が資源を食っているかを見ます。止める前に何なのかを確かめるのが順番です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. nohup は何をしますか。

HUP シグナルを無視させて、ログアウト後もコマンドが生き続けるようにします。バックグラウンドには回してくれないので `&` は自分で付け、出力は静かに ./nohup.out にたまります。

Q. どう打ちますか。

nohup <command> [args] & — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは3個です。全部は man nohup にあります。このコマンドはプロセスとシステムの仲間です。

関連するコマンド

man ページ: man nohup