如何告诉正在运行的进程忽略 SIGHUP?

Sta*_*cek 9 nohup logout

可能的重复:
如何在不终止其中运行的命令的情况下关闭终端?

我有一个运行 Debian Squeeze 的非常低端的“服务器”,我偶尔会通过 ssh 连接到它。系统往往很慢,例如运行apt-cache search可能需要半分钟。有时我发现我迫不及待地等待一个过程完成(我在我的笔记本电脑上,需要去某个地方)。

如果我最初使用nohup或 inside开始该过程screen,这将没有问题。但是,尽管我已注销,但如何让已经在运行的进程继续运行?

Chr*_*own 11

假设您使用的是 bash、ksh、zsh 或其他类似的 shell,您可以将进程后台运行,然后运行disown. 具体来说,在bash您可能想要disown -h.

从 bash 的帮助页面disown

disown: disown [-h] [-ar] [jobspec ...]
    Remove jobs from current shell.

    Removes each JOBSPEC argument from the table of active jobs.  Without
    any JOBSPECs, the shell uses its notion of the current job.

    Options:
      -a        remove all jobs if JOBSPEC is not supplied
      -h        mark each JOBSPEC so that SIGHUP is not sent to the job if the
        shell receives a SIGHUP
      -r        remove only running jobs

    Exit Status:
    Returns success unless an invalid option or JOBSPEC is given.
Run Code Online (Sandbox Code Playgroud)

  • 请注意,这告诉 shell 在 shell 本身收到 SIGHUP 时不要向进程发送 SIGHUP。它不会保护进程从另一个源接收 SIGHUP(如果进程已成为会话领导者,则从终端接收 - 这通常不会发生 - 或显式发送)。 (3认同)

Sté*_*nez 6

如果您使用 bash 或 zsh,请disown在注销前使用内置程序。

来自man zshall

   disown [ job ... ]
   job ... &|
   job ... &!
          Remove the specified jobs from the job table; the shell will  no
          longer  report their status, and will not complain if you try to
          exit an interactive shell with them running or stopped.   If  no
          job is specified, disown the current job.
Run Code Online (Sandbox Code Playgroud)