Re: Strange pager (less, more) behavior
- From: Dave Ulrick <ulrick@xxxxxxxxxxxxxxxx>
- Date: Wed, 29 Mar 2006 15:46:37 +0000 (UTC)
On Wed, 29 Mar 2006 11:56:34 +0200,
Kasper Dupont <31026663590054698937@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Måns Rullgård wrote:
Closing stdout is fine, and the correct thing to do in this case. If
you do not close it, you have no chance of detecting errors in the
final buffer flush.
I'd rather use fflush to check for write errors on stdout.
There is no reason for not closing
stdin/out/err. They are all closed automatically on program exit
anyway, so there is no externally visible difference.
I would worry about what is going to happen when stdio is going
to access stdout on exit. Usually I consider whoever opens a file
responsible to close it again. But if any part of a program copy
a pointer to stdout and eventually close it, you may easilly have
many attempts to close it, and somebody may try to access it after
it has been closed.
If you use strace on the program, there is a visible difference
between calling fclose(stdout) and letting stdio deal with it on
exit. In the first case there is a close(1) system call, there is
none in the second case.
As far as I recall, my code never closes stdout or stderr, but I do
call fflush(stdout) in a number of situations (generally to synchronize
stderr with stdout).
I've seen this happen on occasion as well. It's rare enough that I
haven't tried to figure out why it happens, and I've not been able to
spot any pattern. AFAIK, I've never run any of the OP's programs.
I think I have only seen it happen if I accidentially ran less
in the background.
In that case, you'll see it happen every time. :-)
Dave
--
Dave Ulrick
Email: d-ulrick@xxxxxxx
Web: http://www.niu.edu/~ulrick/
.
- References:
- Strange pager (less, more) behavior
- From: Dave Ulrick
- Re: Strange pager (less, more) behavior
- From: Måns Rullgård
- Strange pager (less, more) behavior
- Prev by Date: Re: Strange pager (less, more) behavior
- Next by Date: Playback utility
- Previous by thread: Re: Strange pager (less, more) behavior
- Next by thread: Re: Strange pager (less, more) behavior
- Index(es):
Relevant Pages
|