Lyle Vogtmann

Tuesday, January 18, 2011

 

How to redirect a running process output to a file and log out

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

Archives

June 2010   December 2010   January 2011  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]