在Debian系统下,使用nohup
命令可以在后台运行程序,即使关闭终端或断开连接,程序也会继续运行
打开终端。
输入以下命令,将your_command
替换为您要运行的程序或脚本的命令:
nohup your_command &
例如,如果您要在后台运行名为my_script.sh
的脚本,可以使用以下命令:
nohup ./my_script.sh &
nohup.out
的文件中。您可以使用以下命令查看输出:tail -f nohup.out
nohup your_command > output_file 2>&1 &
例如,如果您要将输出重定向到名为output.log
的文件,可以使用以下命令:
nohup ./my_script.sh > output.log 2>&1 &
这样,程序的输出将被写入output.log
文件,而不是默认的nohup.out
文件。
nohup your_command > output_file 2>&1 & echo $! > pid_file
这将把进程ID写入名为pid_file
的文件中。您可以使用以下命令查看进程ID:
cat pid_file
然后,您可以使用kill
命令终止进程,例如:
kill $(cat pid_file)