nohup
(no hang-up)命令用于在Linux中使进程在用户退出登录后继续运行
以下是如何使用nohup
命令的步骤:
打开终端。
输入命令 nohup
,后跟你想要运行的命令及其参数。例如,如果你想要在后台运行名为 my_script.sh
的脚本,你可以输入:
nohup ./my_script.sh &
这里的 &
符号表示将进程放入后台运行。
nohup
会自动将输出重定向到名为 nohup.out
的文件中,除非你指定了其他输出文件。例如,如果你想将输出重定向到名为 output.log
的文件,你可以输入:nohup ./my_script.sh > output.log &
tail
命令查看 nohup.out
或 output.log
文件的内容:tail -f nohup.out
或者
tail -f output.log
ps
命令找到进程ID(PID),然后使用 kill
命令终止它。例如:ps aux | grep my_script.sh
找到与你的脚本相关的进程,记下它的PID。然后使用以下命令终止进程:
kill PID
将 PID
替换为实际的进程ID。