[lug] Is there a way to get output once it's been redirected to /dev/null?

Zan Lynx zlynx at acm.org
Fri Jun 25 16:06:31 MDT 2010


On 6/25/10 4:01 PM, Jeffrey Haemer wrote:
> Earlier today, someone came to me with a problem.  I couldn't think of a
> way to solve it, but I believe a logician would rule that "argumentum
> imagi pauco" ("Proof by Lack of Imagination.")
>
> He was logged in to an embedded box on a customer site, trying to debug
> a problem with a running daemon.  The daemon had been started with
> stdout, and stderr both redirected to /dev/null.
>
> "Is there a way," he asked, "to redirect and capture the output without
> restarting the daemon?"
>
> I can probably even argue why there *couldn't possibly* be a way to
> solve it, so that only a moron would think about the problem:
> "argumentum ad territo" ("Proof by Intimidation.")
>
> Ideas?  Suggestions?

There *is* actually a way to do this.

I don't have the links to the program that will do this, but I know it's 
out there somewhere. Or, if sufficiently enterprising, you could write 
one of your own.

What is done, is to use ptrace to attach to the process and then in the 
context of the process while it is paused close() and then open() the 
standard output and standard error file handles so they point where you 
want them.

-- 
Zan Lynx
zlynx at acm.org

"Knowledge is Power.  Power Corrupts.  Study Hard.  Be Evil."



More information about the LUG mailing list