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 | Blog | 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?



[Derek D. Martin: Wed, Jun 05, 2002 at 06:34:03PM -0400]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> At some point hitherto, John Abreau hath spake thusly:
> > You said "under some circumstances"; can you expand on that? When
> > would it *not* work?
> 
> I'm unfamiliar with a lot of the more advanced uses of GDB, but in
> addition to the author's response, I can think of one more case where
> I believe this will not work: where there are no streams involved.
> 
> freopen() opens a file, and reassociates the stream given as the last
> argument with that file.  If the file was opened with open(), there is
> no stream to associate.
> 

the technique works fine with write (1,buf,sz,flags) (fd=1 is always
stdout when main starts) - freopen modifes both the FILE * and the
underlying fd that last part is important! Indeed, stdout=fopen(blah)
won't work at all because it doesn't impact the underlying fd.

try it! That's always the best way. This works fine - no include with
stdio and write directly to STDOUT_FILENO (1) - no streams.


int main(int c, char **v)
{
  while (1)
    {
      write (1,"hey\n",4,0);
      sleep (1);
    }
  return 0;
  
}






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