后台自动执行
nohup [命令] &
nohup(no hang up):可以让程序不挂断执行。
& :可以让程序在后台执行。
日志输出
nohup [命令] > nohup.log 2>&1 &
“> nohup.log”: 表示将日志输出到nohup.log文件上。
2>&1:表示将正确日志、错误日志都输出到正确日志指定的文件(nohup.log文件)上。
完整的linux后台自动执行、输入日志到指定文件命令
nohup [命令] > nohup.log 2>&1 &
例如:
nohup python3 test.py > nohup.log 2>&1 &
该命令表示:
在后台用python3不挂断执行test.py脚本代码,并将正确、错误日志输出到nohup.log文件。
实时刷新查看日志
tail -f nohup.log
查看当前进程号(可能会起两个进程要杀死两次)
ps -ef | grep xxx