nohup和&,进程后台运行、查看、终止

nohup 命令可以使命令永久的执行下去,和终端没有关系,退出终端也不会影响程序的运行;
& 是后台运行的意思,但当用户退出的时候,命令自动也跟着退出。
那么,把两个结合起来nohup 命令 &这样就能使命令永久的在后台执行

run_train.sh文件为例

source env_set.sh

nohup python -u train_image_classifier.py \
  --dataset_name=$DATASET_NAME \
  --dataset_dir=$DATASET_DIR \
  --checkpoint_path=$CHECKPOINT_PATH \
  --model_name=inception_v4 \
  --checkpoint_exclude_scopes=InceptionV4/Logits,InceptionV4/AuxLogits/Aux_logits \
  --trainable_scopes=InceptionV4/Logits,InceptionV4/AuxLogits/Aux_logits \
  --train_dir=$TRAIN_DIR \
  --learning_rate=0.001 \
  --learning_rate_decay_factor=0.76\
  --num_epochs_per_decay=50 \
  --moving_average_decay=0.9999 \
  --optimizer=adam \
  --ignore_missing_vars=True \
  --batch_size=32 > output.log 2>&1 &

    
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

TensorFlow中运行程序,在run_train.sh文件前后添加nohup 命令 > output.log 2>&1 &让命令在后台执行。

其中 0、1、2分别代表如下含义:
0 – stdin (standard input)
1 – stdout (standard output)
2 – stderr (standard error)

nohup+最后面的&是让命令在后台执行

>output.log 是将信息输出到output.log日志中

2>&1是将标准错误信息转变成标准输出,这样就可以将错误信息输出到output.log 日志里面来。


  • 查看日志(动态显示)

    tail -f output.log
          
          
    • 1
  • 查看日志(一次性显示整个文件)

    cat output.log
          
          
    • 1

  • 查看当前Python进程

    ps -ef |grep python
          
          
    • 1
  • 杀死进程

    sudo kill 进程号
          
          
    • 1
    kill 9 进程号 #绝杀
          
          
    • 1

nohup 命令可以使命令永久的执行下去,和终端没有关系,退出终端也不会影响程序的运行;
& 是后台运行的意思,但当用户退出的时候,命令自动也跟着退出。
那么,把两个结合起来nohup 命令 &这样就能使命令永久的在后台执行

run_train.sh文件为例

source env_set.sh

nohup python -u train_image_classifier.py \
  --dataset_name=$DATASET_NAME \
  --dataset_dir=$DATASET_DIR \
  --checkpoint_path=$CHECKPOINT_PATH \
  --model_name=inception_v4 \
  --checkpoint_exclude_scopes=InceptionV4/Logits,InceptionV4/AuxLogits/Aux_logits \
  --trainable_scopes=InceptionV4/Logits,InceptionV4/AuxLogits/Aux_logits \
  --train_dir=$TRAIN_DIR \
  --learning_rate=0.001 \
  --learning_rate_decay_factor=0.76\
  --num_epochs_per_decay=50 \
  --moving_average_decay=0.9999 \
  --optimizer=adam \
  --ignore_missing_vars=True \
  --batch_size=32 > output.log 2>&1 &

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

TensorFlow中运行程序,在run_train.sh文件前后添加nohup 命令 > output.log 2>&1 &让命令在后台执行。

其中 0、1、2分别代表如下含义:
0 – stdin (standard input)
1 – stdout (standard output)
2 – stderr (standard error)

nohup+最后面的&是让命令在后台执行

>output.log 是将信息输出到output.log日志中

2>&1是将标准错误信息转变成标准输出,这样就可以将错误信息输出到output.log 日志里面来。


  • 查看日志(动态显示)

    tail -f output.log
        
        
    • 1
  • 查看日志(一次性显示整个文件)

    cat output.log
        
        
    • 1

  • 查看当前Python进程

    ps -ef |grep python
        
        
    • 1
  • 杀死进程

    sudo kill 进程号
        
        
    • 1
    kill 9 进程号 #绝杀
        
        
    • 1

猜你喜欢

转载自blog.csdn.net/dby_freedom/article/details/80212107