01-22-05 10:49 PM
Dexter <vikram_ramakrishnan@ieee.org> wrote:
> I have a process that is running for a long time. It has all its output
> redirected to a file.When i start the program i redirect both stderr
> and stdout to the log file.
> All the output comes to the files only after the program terminates or
> in some cases after 5-6 hrs.
> Is there a way that i can force the program to dump its buffers to the
> log files when it is running.
> i know i can change the code to print all its output to stderr so that
> it gets printed immediatly but just wanted to know if theres another
> way.
Since you seem to have access to the code it's rather simple. Either add
a fflush(3) call after each (f)printf() to stdout or use setvbuf(3) to
switch buffering to either line buffering or unbuffered. I.e. a line
like
setvbuf( stdout, NULL, _IOLBF, 0 );
or
setvbuf( stdout, NULL, _IONBF, 0 );
will do. Of course, that's assuming your using C (or C++). But most
other languages should also have methods to do that, in e.g. Perl
use
$| = 1;
to switch the currently selected output handle to unbuffered mode.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
[ Post a follow-up to this message ]
|