I can't remember how I found this now, but I at least emailed it to myself to remind me about it later. I usually keep
tmux or
screen running on all my systems, but I do occasionally forget to re-attach, and end up running something (compilation, download, indexing, etc...) that will take a while to complete. Note that I already know about
nohup, this tip is in regards to those situations I realize I must close my shell before a long running command completes but has already been started.
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
detach
quit
# Back in shell
disown
logout