如何防止后台进程在Linux中关闭SSH客户端后停止

2024-04-25 13:53:45 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

当会话关闭时,进程接收到它显然没有捕捉到的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.

我建议使用GNU Screen。它允许您在所有进程继续运行时断开与服务器的连接。在我知道它存在之前,我不知道没有它我是怎么生活的。

查看“nohup”程序。

相关问题 更多 >