0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

nohupで長時間プログラムを走らせる

0
Last updated at Posted at 2026-10-10

nohup

IBMのサイトより引用

nohup コマンドは、Command パラメーターおよび関連する Arg パラメーターで指定されたコマンドをハングアップ・シグナル (SIGHUP) をすべて無視して実行するか、-p オプションで指定されたプロセスを変更して SIGHUP シグナルをすべて無視するようにします。 SIGHUP は、プロセスの制御端末がクローズされたときにプロセスに送信されるシグナルです。
IBM1

具体的な実行方法

長時間動作させたいプログラムを実行するシナリオを考える。
標準出力と標準エラー出力に書き出されるログをテキストファイルに書き出し、かつこれをバックグラウンドで実行したい。

こういった時には、以下の形式でコマンドを実行する。

nohup ${実行コマンド} > output.log 2>&1 &

例:main.pyというPythonプログラムを動かす

nohup python3 main.py > output.log 2>&1 &

この場合、python3 main.pyが実行したいコマンドになる。

以下細い説明。

  • nohup : SIGNUPを無視
  • python3 main.py : pythonプログラムを実行するコマンド
  • > output.log : 実行したpythonプログラムの標準出力をリダイレクトしoutput.logに書き出す
  • 2>&1 : 標準エラー出力を標準出力に出力する命令
  • & : 上記の命令をバックグラウンドプロセスで実行する命令
  1. https://www.ibm.com/docs/ja/aix/7.3.0?topic=n-nohup-command#nohup__title__4 ↩

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?