9

Possible Duplicate:
How can I close a terminal without killing the command running in it?

I have a very low-end "server" running Debian Squeeze that I occasionally ssh to. The system tends to be slow, e.g. running apt-cache search might take half a minute. Occasionally I find that I can't wait for a process to complete (I'm on my laptop and need to go somewhere).

If I had originally started the process with nohup or inside screen, this would be no problem. But how can I get an already running process to continue despite my logging off?

2 Answers2

11

On the assumption that you are using bash, ksh, zsh, or another similar shell, you can background the process, then run disown. Specifically, in bash you probably want disown -h.

From bash's help page on 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.
Chris Down
  • 125,559
  • 25
  • 270
  • 266
  • Great! I thought something like this must exist. Thanks! – StackExchange saddens dancek Nov 12 '11 at 15:25
  • 3
    Note that this tells the shell not to send a SIGHUP to the process when the shell itself receives a SIGHUP. It won't protect the process from receiving a SIGHUP from another source (either from the terminal if the process has become a session leader — which doesn't typically happen — or sent explicitly). – Gilles 'SO- stop being evil' Nov 12 '11 at 19:58
  • True, but there is no way to do that (aside from changing the way that the program were to handle SIGHUP, but that would require a source change). – Chris Down Nov 12 '11 at 20:48
6

If you use bash or zsh use the built-in disown before logging off.

From 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.