Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I run a lot of long running processes (simulations) that print progress to STDOUT. I occasionally forget to redirect to STDOUT to a file I can grep, and it's usually too far along to restart.

QUESTION: Without stopping the process, is there a way I can hook into another STDOUT?

These are always running in GNU screen with ZSH on OS X 10.7.3.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

There is a clever hack mentioned here that uses GDB to attach to the process, and a utility named dupx wraps up this functionality.

From the dupx manpage:

Dupx is a simple utility to remap files of an already running program. Shells like Bash allow easy input/output/error redirection at the time the program is started using >, < - like syntax, e.g.: echo 'redirect this text' > /tmp/stdout will redirect output of echo to /tmp/stdout.

Standard shells however do not provide the capability of remapping (redirecting) of output (or input, or error) for an already started process. Dupx tries to address this problem by using dup(2) system call from inside gdb(1). Dupx is currently implemented as a simple shell wrapper around a gdb script.

share|improve this answer
    
Thanks! I had to make some modifications, but it does exactly what I need. –  jmdeldin Mar 24 '12 at 20:45
    
You're welcome! Glad you got it to work. –  Matt Eckert Mar 24 '12 at 20:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.