Skip to content

Instantly share code, notes, and snippets.

@zaius
Created January 16, 2011 23:29
Show Gist options
  • Select an option

  • Save zaius/782263 to your computer and use it in GitHub Desktop.

Select an option

Save zaius/782263 to your computer and use it in GitHub Desktop.
How to redirect a running process output to a file and log out
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
@ogier
Copy link

ogier commented Jan 17, 2011

Thomas, I think you missed the point of the gist. This makes sense if you have a process already running and later realize you need to disown it without losing its output. I for one run into this problem often and I really like this solution.

@nnutter
Copy link

nnutter commented Jan 17, 2011

This was linked on Hacker News and in the comments there julian37 pointed out that someone created a bash script to do this called "Dupx".
http://www.isi.edu/~yuri/dupx/

Edit: And of course, thank you to bringing this tool to my attention. Very useful.

@otonoton
Copy link

otonoton commented Dec 13, 2025

@nnutter Got a backup copy of dupx? That link is dead.

@nnutter
Copy link

nnutter commented Dec 15, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment