How can I close a terminal without killing its children (without running `screen` first)?

If some-boring-process is running in your current bash session:

  1. halt it with ctrl-z to give you the bash prompt
  2. put it in the background with bg
  3. note the job number, or use the jobs command
  4. detach the process from this bash session with disown -h %1 (substitute the actual job number there).

That doesn't do anything to redirect the output -- you have to think of that when you launch your boring process. [Edit] There seems to be a way to redirect it https://gist.github.com/782263

But seriously, look into screen. I have shells on a remote server that have been running for months.


Looks like this:

$ sleep 999999
^Z
[1]+  Stopped                 sleep 999999
$ bg
[1]+ sleep 999999 &
$ disown -h %1

This is exactly what screen and tmux were created for. You run the shell inside the screen/tmux session, and you can disconnect/reconnect at will. You can also have multiple shell sessions running inside one gnome-terminal.


screen, tmux, or dtach (possibly with dvtm) are all great for this, but if it's something where you didn't think to use one of those, you may be able to leverage nohup.