在Debian系统中,nohup命令用于在后台运行程序,即使关闭终端或注销用户,程序也会继续运行
打开终端。
使用nohup命令启动程序。基本语法如下:
nohup 命令 [参数] &
例如,如果你想在后台运行名为my_script.sh的脚本,可以使用以下命令:
nohup ./my_script.sh &
这将在后台运行my_script.sh,并将输出重定向到名为nohup.out的文件。
nohup 命令 [参数] > 输出文件 2>&1 &
例如,将输出重定向到output.log文件:
nohup ./my_script.sh > output.log 2>&1 &
按下回车键运行命令。程序将在后台运行,即使关闭终端或注销用户,程序也会继续运行。
若要检查程序的输出,可以查看nohup.out文件或其他指定的输出文件:
cat nohup.out
或者
cat output.log
tail命令:tail -f nohup.out
或者
tail -f output.log
这样,你就可以在Debian中使用nohup命令避免进程被终止。