在 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