LinuxにおけるNohupコマンド
Linux システムのシェルから抜けると、通常は実行中のプロセスは終了するか待機状態になります。しかし、シェル/ターミナルを終了してもプロセスを継続させたい場合は、どうすれば良いでしょうか? それが nohup コマンドの登場する場面です。
「Nohupコマンドの日本語での言い換えを1つのオプションで教えてください」
ノーハングアップ(No hang up)の略称である「Nohup(ノーハプ)」は、Linuxシステムでのコマンドです。このコマンドを使用すると、シェルやターミナルを終了した後でもプロセスを実行し続けることができます。Nohupは、プロセスやジョブが「SIGHUP(シグナルハングアップ)」シグナルを受け取らないようにします。このシグナルは、ターミナルを閉じたり終了した際にプロセスに送信されるものです。このガイドでは、Nohupコマンドの使用方法について紹介します。
Nohupコマンドの構文
「Nohupコマンドの構文は以下の通りです。」
nohup command arguments
または、
nohup options
「どのようにコマンドが活躍するか、見てみましょう」
Nohupのバージョンを確認する。
以下の構文を使用して、Nohupのバージョンをチェックすることができます。
nohup --version

Nohupを使用してプロセスを開始する。
以下のように、プロセス/ジョブを実行し続けたい場合には、コマンドの前にnohupを付けてください。ジョブはシェル内で引き続き実行され、シェルやターミナルを終了しても終了しません。
nohup ./hello.sh

cat nohup.out

nohup ./hello.sh > output.txt
再び、ファイルを閲覧するために実行してください。 (Futatabi, fairu oetsubetsu suru tame ni jikkō shite kudasai.)
cat output.txt

nohup ./hello.sh > myoutput.txt >2&1

Nohupを使用してバックグラウンドでプロセスを開始する。
コマンドの末尾に&シンボルを使用して、バックグラウンドでプロセスを開始します。この例では、google.comにpingを送ってバックグラウンドで実行しています。
nohup ping google.com &

pgrep -a ping

kill 2565

要約
-
- nohupコマンドを使用して実行されるすべてのプロセスは、シグナルSIGHUPを無視します。シェルから終了しても同様です。
-
- nohupコマンドを使用してジョブを開始または実行すると、stdinはユーザーに利用できなくなります。
- デフォルトでは、nohup.outがstdoutとstderrのデフォルトファイルとして使用されます。