teeing parent+childs output

H

-H

Hi,

I have a "parent" C program that forks off a "child" C program.
Both the parent and the child print information to both stdout and
stderr.

I would like to redirect the parent and childs output to both stdout
and an output logfile (in effect, a "tee" like behavior).

I've tried several things with pipes and freopens, but I always seem
to get data out of synch. :(

Any help on this would be greatly appreciated!
Please cc replies to (e-mail address removed).
Thanks in advance.

- H
 
D

Derk Gwen

(e-mail address removed) (-H) wrote:
# Hi,
#
# I have a "parent" C program that forks off a "child" C program.
# Both the parent and the child print information to both stdout and
# stderr.
#
# I would like to redirect the parent and childs output to both stdout
# and an output logfile (in effect, a "tee" like behavior).
#
# I've tried several things with pipes and freopens, but I always seem
# to get data out of synch. :(

Each process has its own buffers. To force output to a device, you need to use
fflush or turn off bufferring with setvbuf. This can slow the program down.
 
B

Bryan Donlan

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- -H said:
Hi,

I have a "parent" C program that forks off a "child" C program.
Both the parent and the child print information to both stdout and
stderr.

forking isn't in the ISO C specification. Try comp.unix.programmer.
- --
Freenet distribution not available
You're not an alcoholic unless you go to the meetings.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/QYiFx533NjVSos4RAm4EAJ42knygi5fzBMic+nW1KSbZm973CQCdER2+
lEG1ZU/uEMh0YUx36U/KL54=
=+hIu
-----END PGP SIGNATURE-----
 
J

Jack Klein

(e-mail address removed) (-H) wrote:
# Hi,
#
# I have a "parent" C program that forks off a "child" C program.
# Both the parent and the child print information to both stdout and
# stderr.
#
# I would like to redirect the parent and childs output to both stdout
# and an output logfile (in effect, a "tee" like behavior).
#
# I've tried several things with pipes and freopens, but I always seem
# to get data out of synch. :(

Each process has its own buffers. To force output to a device, you need to use
fflush or turn off bufferring with setvbuf. This can slow the program down.

Can you cite the section in either the C or C++ standard that defines
what each process has? If not, don't post this drivel here.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top