Hacker News new | past | comments | ask | show | jobs | submit login
Redirect a running process output to a file and log out (gist.github.com)
121 points by zaius on Jan 16, 2011 | hide | past | favorite | 13 comments



Explained with comments: https://gist.github.com/782312 (edit: made clearer).


Nice. Thanks for that. The only addendum I would make is that the second parameter to open specifies to open the file as writable. Usually the constant is O_WRONLY, but it wasn't working for me in GDB.


Wow, I get that the gdb stuff is the real clever trickery, but 'disown' is the most valuable thing I got from that. I knew about nohup, but I didn't know about disown.


Disown is actually implemented by bash (or your shell of choice). From my understanding, it just stops the HUP propagating down to that child. There might be a more shell-agnostic way to assign the parent process id too.


Someone has rolled this into a script:

http://www.isi.edu/~yuri/dupx/


This always annoys me:

Dupx is currently implemented as a simple shell script

So why can't I just download this "simple shell script"?


Extract it from the provided tarball. Almost as easy, but with no man page.


duh


Alternatively, if you know you're going to want to do this beforehand, check out the 'nohup' command. It does basically the same thing with any command it's given.

http://en.wikipedia.org/wiki/Nohup


Is this better than running the program in something like screen or tmux?


I get the impression that this is for when you've forgotten to set up something like screen beforehand.


Am I a bad person for using nohup and stderr/stdout redirect?

Anyway this is a really nice creative alternative.


Actually, it's not meant as an alternative, but when you forgot to use nohup or stderr/stdout redirect, ie. redirect output from an already running process.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: