Flush Buffers of another process.
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Flush Buffers of another process.




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Flush Buffers of another process.  
Dexter


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-22-05 07:48 AM

Hi,

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.

Any pointers or info would be helpful.

-Thanks,
Dexter.






[ Post a follow-up to this message ]



    Re: Flush Buffers of another process.  
Jens.Toerring@physik.fu-berlin.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: Flush Buffers of another process.  
Dexter


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-05 12:47 PM

yeah i understand i can do it. but is there a way without changing the
code.?






[ Post a follow-up to this message ]



    Re: Flush Buffers of another process.  
Dexter


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-05 12:47 PM

yeah i understand i can do it. but is there a way without changing the
code.?






[ Post a follow-up to this message ]



    Re: Flush Buffers of another process.  
Jens.Toerring@physik.fu-berlin.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-05 12:48 PM

Dexter <vikram_ramakrishnan@ieee.org> wrote:
> yeah i understand i can do it. but is there a way without changing the
> code.?

No. What you can do is trick the program into assuming that it's
writing to a terminal (instead of a file), thus making it run in
line buffered instead of fully buffered mode (when a program gets
started it calls isatty(3) to figure out what stdout is connected
to). I guess the best method is to invoke the program from a wrapper
that creates a pseudo terminal and exec's the program with stdin,
stdout and stderr redirected to the pty. Then, in the wrapper, read
the output from the program and write it yourself to the file in
line buffered mode. Perhaps having a look at "expect" and the
library it uses, "libexpect", will be also interesting for you.

Regards, Jens
--
\   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
\__________________________  http://www.toerring.de





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:27 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register