Instrucciones:
# 使用 & 使程序后台运行
python test.py &
#使用 nohup 是程序后运行
nohup python test.py
#后台执行程序 (推荐此方法)
nohup python test.py > /dev/null 2>&1 &
Descripción
*****************************************************************
此处的/dev/null可以替换成xxxx.log这种日志文件,可以方便后期debug
*****************************************************************
/dev/null 表示空设备文件
0 表示stdin标准输入
1 表示stdout标准输出
2 表示stderr标准错误
>/dev/null 表示将标准输出输出到/dev/null中,也就相当于 1>/dev/null
2 > error 表示将错误输出到error文件中
2>&1 也就表示将错误重定向到标准输出上
2>&1 >xxx.log :错误输出到终端,标准输出重定向到文件xxx.log中
相当于 >xxxx.log 2>&1(标准输出重定向到文件,错误重定向到标准输出)。
& 放在命令到结尾,表示后台运行,防止终端一直被某个进程占用,这样终端可以执行别到任务
配合 >xxxx.log 2>&1可以将log保存到xxxx.log文件中
但如果终端关闭,则进程也停止运行。如 command > xxxx.log 2>&1 &
nohup放在命令的开头,表示不挂起(no hang up)
所以关闭终端或者退出某个账号,进程也继续保持运行状态,一般配合&符号一起使用。如nohup command &。
La diferencia entre nohup y &
- Razón :
&
DeSIGINT
inmunidad a las señales, porSIGHUP
no inmunesnohup
De laSIGINT
señal no es inmune a laSIGHUP
inmunidad.
- El resultado :
&
Incluso si usa Ctrl+, el Cprograma se ejecuta como de costumbre, pero después de cerrar el terminal Shell, el proceso del programa desaparece.hohup
Después de cerrar el terminal Shell, el proceso del programa aún existe, pero el programa Ctrl+ en el terminal Cdesaparecerá.
- Descripción
-
Para que el proceso no se vea realmente afectado por el Ctrl+ Cy el cierre de la cáscara en la cáscara, se recomienda utilizar
nohup command &
-
Si necesita ver el error estándar de la impresión intermedia, puede usar
nohup command > xxx.log 2>&1 &
-