Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HELP - Redirect output of already running process?



[John Abreau: Wed, Jun 05, 2002 at 02:37:41PM -0400]
> 
> Can't be done.

Actually under some circumstances it can be done by attaching with gdb
and reopening stdout.. Its not unlike highwire walking.

/home/mcmanus/t>more g.c
#include <stdio.h>

int main(int c, char **v)
{
  while (1)
    {
      fprintf (stdout,"hello\n");
      sleep (1);
    }
  return 0;
}

/home/mcmanus/t>./a.out &
[3] 11377
hello
hello
hello

/home/mcmanus/t>gdb a.out 11377

GNU gdb Red Hat Linux (5.1.90CVS-5)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
Attaching to program: /home/mcmanus/t/a.out, process 11377
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
0x400dc181 in nanosleep () from /lib/libc.so.6
(gdb) print freopen ("log","w",stdout)
$1 = 1075145472

(gdb) The program is running.  Quit anyway (and detach it)? (y or n) y
Detaching from program: /home/mcmanus/t/a.out, process 11364

/home/mcmanus/t> [wait a few seconds in blissful quiet]

/home/mcmanus/t>cat log
hello
hello
hello

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://lists.blu.org/pipermail/discuss/attachments/20020605/6b3e7ab3/attachment.sig>



BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org