Re: Strange pager (less, more) behavior
- From: mru@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (Måns Rullgård)
- Date: 29 Mar 2006 11:13:41 GMT
Kasper Dupont
<97619472400731189722@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
writes:
Dave Ulrick wrote:command
Hi,
Presently, I'm developing a set of C programs that run via the
line and exclusively use standard C library stream I/O: fopen,fputs,
fprintf, fclose, etc.. As a convenience to the user, I allow manyof
the output files to be defaulted to stdout or stderr. For instance,Closing stdout is fine, and the correct thing to do in this case. If
a message log file might default to stderr. My file open logic for
such files amounts to something like this:
FILE *f;
char *filename;
if (!filename || strcmp (filename, "-") == 0)
f = stdout;
else
f = fopen (filename, "w");
In such a manner, my programs frequently assign stdout and stderr
to program-defined FILE pointers, but I _never_ assign values to
stdout or stderr, and I never use freopen. As far as I've been able
to tell from C programming books and the Internet, my use of
stdout and stderr is legitimate.
That is a perfectly valid way to use stdout. But then you'd
have to look on filename again to figure out if you need to
call fclose. Or you could just compare the pointers:
if (f != stdout) fclose(f);
you do not close it, you have no chance of detecting errors in the
final buffer flush. 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.
However, I've noticed on my Linux 2.6.9 (and above) PCs that atstrange
least some of my programs sometimes gets involved in a rather
bit of (mis)behavior when I pipe its output to a pager such as'less'
or 'more'. When I do this, my command line looks something likenot
this:
$ ./myprogram 2>&1 | less
99.44% of the time, this works perfectly, but every once in a while,
the pager doesn't appear. Instead, 'bash' gives me these messages:
[1]+ Stopped ./myprogram 2>&1 | less
as though I'd pressed Ctrl-Z to stop the pipeline even though I've
pressed any such key. 'ps auxw' reveals that my program hascompleted
I've seen this happen on occasion as well. It's rare enough that I
This sounds a bit strange. When you say it happens with
grep do you mean something like
./myprogram 2>&1 | grep foobar | less
or is it a command line not even involving your own program?
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.
--
Måns Rullgård
mru@xxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Strange pager (less, more) behavior
- From: Dave Ulrick
- Re: Strange pager (less, more) behavior
- References:
- Strange pager (less, more) behavior
- From: Dave Ulrick
- Strange pager (less, more) behavior
- Prev by Date: Re: feature tests for pthreads implementation and configuration?
- Next by Date: Re: feature tests for pthreads implementation and configuration?
- Previous by thread: Re: Strange pager (less, more) behavior
- Next by thread: Re: Strange pager (less, more) behavior
- Index(es):
Relevant Pages
|