The following is the same on AT&T UNIX V.3 and V.4.
The scenario is that a program (a background communication interface) is
invoked, and it fork()s 2 children. The parent monitors both children, and
one child deals with inbound traffic, the other with outbound traffic.
In this program, we have a lot of printf()s used for debugging and tracing, and
are only active when we compile with a -DDEBUG compiler flag.
We let the program run in the background, and redirect stdout, and stderr to a
holding debug file, via the shell command:
prog > debug.out 2>&1
Because "prog" breaks itself into three running processes, we have three
different processes redirecting their output to the debug file.
The problem is that the file does not contain things in chronological order.
What happens is that it will contain output from the parent, then output from
child1, then output from child2, all interspersed.
I assume this is because of system buffering for printf()s.
Of course I can rewrite the printf()s so as they would write to a special log
file, but this would be a considerable effort, plus it will deprive us of the
flexibility of displaying output directly to the terminal when we want to.
What is an easy way to get the output of all three processes correctly in
correct chronological order?
Thanks in advance.
Khalid M. Bahey-elDin | Voice: +966-2-651-2727 | Fax: +966-2-651-8804
P.O.Box 13964, Jeddah 21414 | UUCP: ..!uunet!ncrlnk!ncrsaud!kbahey