[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Flushing all Buffers Before Exiting



On Thu 21 Mar 2019 at 11:35:51 (-0500), Martin McCormick wrote:

> 	I wrote the application that is creating this output in
> perl and there may be a unique solution there that solves this specific
> problem.  That is not as good as a general course of action which
> works in all cases of output redirection but it beats nothing.
> 	A suggestion on a posting in stackoverflow was that one
> could open the file for appending, append your new output and
> then close it.

An efficient way of doing this is to trap a signal, like USR1,
in your program, and react by either your close/open-append or
just flushing the buffers. That way, the program will run
normally most of the time, without wasting all that time
opening/closing files.

If there's not too much output compared with the computation necessary
to generate it, just setting line-buffering on the output stream
can be sufficient.

I've read that when the program is already running, some languages
(like Python, so probably Perl too) offer a debugger that can
allow you to flush the buffers from "within", but I've not tried
it.

Cheers,
David.


Reply to: