在 CentOS 系统中,nohup
命令用于在后台运行程序,即使关闭终端或注销用户,程序也会继续运行
打开终端。
使用 nohup
命令运行你的程序。基本语法如下:
nohup command-to-run &
其中,command-to-run
是你要运行的命令,&
符号将命令放入后台运行。
例如,如果你想在后台运行名为 my_script.sh
的脚本,可以使用以下命令:
nohup ./my_script.sh &
nohup: ignoring input and appending output to 'nohup.out'
这意味着程序的输出已被重定向到名为 nohup.out
的文件中。你可以使用文本编辑器查看此文件,以检查程序的输出。
nohup command-to-run > output-file 2>&1 &
例如,将输出重定向到名为 output.log
的文件:
nohup ./my_script.sh > output.log 2>&1 &
这样,程序的标准输出和错误输出都将被写入 output.log
文件。
tail
命令:tail -f output.log
这将实时显示 output.log
文件的内容。
通过以上步骤,你可以使用 nohup
命令在 CentOS 中运行程序,即使关闭终端或注销用户,程序也会继续运行。