By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

teeing parent+childs output

P: n/a
-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 ar*******@yahoo.com.
Thanks in advance.

- H
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ar*******@yahoo.com (-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.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
I have no idea what you just said.
I get that alot.
Nov 13 '05 #2

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- -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.


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+nW1KSbZm973CQ CdER2+
lEG1ZU/uEMh0YUx36U/KL54=
=+hIu
-----END PGP SIGNATURE-----
Nov 13 '05 #3

P: n/a
On Tue, 19 Aug 2003 00:06:12 -0000, Derk Gwen <de******@HotPOP.com>
wrote in comp.lang.c:
ar*******@yahoo.com (-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
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.