一、使用nohup生成后台进程
参考:bash - Getting ssh to execute a command in the background on target machine - Stack Overflow
假定我们需要在终端输入的指令为command,则运行:
nohup command > foo.log 2> foo.err < /dev/null &
如:我们要运行python train.py,则在终端输入:
nohup python train.py > foo.log 2> foo.err < /dev/null &
用开头的nohup和结尾的&让程序在后台运行。在对应目录下我们可以看到生成了一个foo.log和foo.err。
二、如何关闭nohup生成的进程呢?
参考:
linux - How to get the process ID to kill a nohup process? - Stack Overflow
kill -9 后面接ps -ef | grep nohup指令得到的父进程(ps指令得到的第二个进程)即可。