LoginSignup
7
5

More than 5 years have passed since last update.

【nohup】ssh先でセッションが切れてもプロセスをkillされない方法

Last updated at Posted at 2017-11-01

1. はじめに

  • 実行時間が長い以下のようなスクリプトをssh先で動かしたい方のために書いています
    • データ分析
    • ディープラーニングのデータセット作成、学習

2. バックグラウンドでスクリプトを動かす

簡単に使いたい人↓

 $ nohup (コマンド) &

使用例↓

例.1) 単純に
 $ nohup test_script.py &
例.2) 引数がある場合
 $ nohup test_script.py 10 &

3. 別セッションで実行状況を確認する場合

  • バックグラウンドで実行しているため、標準出力に実行状況を表示するような記述になっていても表示されません
  • 『nohup』はデフォルトで『nohup』を動かしたディレクトリに、ログを出力します

そこで、実行状況を確認する方法として『tail -f nohup.out』が有効です

利用例)

1. バックグラウンドで処理を実行

$ nohup test_script.py &

2. session kill
$ (ctrl + d)

3. 再度 ssh
$ ssh user@host

4. 作業ディレクトリへ移動
$ cd (nohupを実行したディレクトリ)

5. ログの出力
$ tail -f nohup.out

追記.1 python コマンドに-uをつけると毎秒printを監視してくれます

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