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

Jeffrey Haemer jeffrey.haemer at gmail.com
Fri Jun 25 16:30:27 MDT 2010


Great idea, but I'm missing something.

Here's the source for a sample program:

#include <stdio.h>

int main(void) {
  while (1) {
    printf("hello, world\n");
    sleep(1);
  }
}

I run it as a daemon, like this:

./hello &>/dev/null &

I use strace -p <pid> to attach to the running process, and get this:

...
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({1, 0}, 0xbfbda924)           = 0
...

I'm looking for "hello, world" .

I've also tried strace -e write=1,2 -p <pid> , with no better luck.


On Fri, Jun 25, 2010 at 4:04 PM, Jonathan Corbet <corbet at lwn.net> wrote:

> On Fri, 25 Jun 2010 16:01:11 -0600
> Jeffrey Haemer <jeffrey.haemer at gmail.com> wrote:
>
> > 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'd use "strace -p" to attach to the daemon, plus a few arguments to
> narrow the output as desired.
>
> jon
>



-- 
Jeffrey Haemer <jeffrey.haemer at gmail.com>
720-837-8908 [cell],  @goyishekop [twitter]
http://seejeffrun.blogspot.com [blog],
http://www.youtube.com/user/goyishekop [vlog]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20100625/3ea60864/attachment.html>


More information about the LUG mailing list