我正在通过SSH (Putty)在Linux机器上工作。我需要让一个进程在夜间运行,因此我认为可以通过在后台启动该进程(在命令末尾使用&号)并将stdout重定向到一个文件来实现这一点。
令我惊讶的是,这行不通。只要我关闭Putty窗口,进程就会停止。
我怎样才能防止这种情况发生?
我正在通过SSH (Putty)在Linux机器上工作。我需要让一个进程在夜间运行,因此我认为可以通过在后台启动该进程(在命令末尾使用&号)并将stdout重定向到一个文件来实现这一点。
令我惊讶的是,这行不通。只要我关闭Putty窗口,进程就会停止。
我怎样才能防止这种情况发生?
当前回答
还有开源libslack包的daemon命令。
Daemon是相当可配置的,并且关心所有繁琐的守护进程的东西,如自动重启、日志记录或pidfile处理。
其他回答
nohup blah &
用您的进程名替换blah!
当会话关闭时,进程接收到SIGHUP信号,但它显然没有捕捉到这个信号。您可以在启动进程时使用nohup命令,或者在启动进程后使用bash内置命令disown -h来防止这种情况发生:
> help disown
disown: disown [-h] [-ar] [jobspec ...]
By default, removes each JOBSPEC argument from the table of active jobs.
If the -h option is given, the job is not removed from the table, but is
marked so that SIGHUP is not sent to the job if the shell receives a
SIGHUP. The -a option, when JOBSPEC is not supplied, means to remove all
jobs from the job table; the -r option means to remove only running jobs.
使用屏幕。它使用起来非常简单,就像终端的vnc一样。 http://www.bangmoney.org/presentations/screen.html
还有开源libslack包的daemon命令。
Daemon是相当可配置的,并且关心所有繁琐的守护进程的东西,如自动重启、日志记录或pidfile处理。
我建议使用GNU屏幕。它允许您在所有进程继续运行时断开与服务器的连接。在我知道它存在之前,我不知道没有它是怎么生活的。