在 CentOS 中,nohup
命令用于在系統后臺運行程序,即使您關閉終端或注銷系統,程序也會繼續運行
打開終端。
輸入以下命令以使用 nohup
運行程序:
nohup your_command &
將 your_command
替換為您要運行的命令。例如,如果您想在后臺運行 Python 腳本,您可以輸入:
nohup python3 my_script.py &
nohup.out
的文件中。如果您想將輸出重定向到其他文件,可以使用以下語法:nohup your_command > output_file.log &
例如,將 Python 腳本的輸出重定向到名為 output.log
的文件中:
nohup python3 my_script.py > output.log &
exit
命令關閉終端,程序將繼續在后臺運行。注意:nohup
命令不會阻止程序接收到信號,例如 SIGTERM
。如果您需要阻止程序接收信號,可以使用 disown
命令。要將程序的輸出從 nohup.out
重定向到其他文件并阻止程序接收信號,您可以使用以下命令:
nohup your_command > output_file.log 2>&1 & disown