03-27-2011
Why must flush all line-buffered output streams?
Hi,
Mentioned in Stevens & Rago "Advanced Programming in the UNIX"
Quote:
whenever input is requested through the standard I/O library from either (a) an unbuffered stream or (b) a line-buffered stream (that requires data to be requested from the kernel), all line-buffered output streams are flushed. The reason for the qualifier on (b) is that the requested data may already be in the buffer, which doesn't require data to be read from the kernel. Obviously, any input from an unbuffered stream, item (a), requires data to be obtained from the kernel.
I don't understand why must flush all line-buffered output streams when (a)an unbuffered or (b)a line-buffered stream require data from kernel?
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Ok, so I have a shell script which runs a specific command, and that command sends it's output to the display. At certain times, the command sends buffered output, and at other times, the command sends unbuffered output in the form of a % progress bar, so if I run the command, the output I receive... (0 Replies)
Discussion started by: vikingshelmut
0 Replies
2. UNIX for Advanced & Expert Users
Hi All,
I am talking about unix col(1) command used for some reverse line filtering etc.
And I notice that the stdout of this command is line buffered i.e. the stdout will flush the data in its buffer line by line. So the number of writes performed by stdout are more.
So now if I make stdout... (0 Replies)
Discussion started by: sunilsbjoshi
0 Replies
3. HP-UX
Hi All,
I am talking about unix col(1) command used for some reverse line filtering etc.
And I notice that the stdout of this command is line buffered i.e. the stdout will flush the data in its buffer line by line. So the number of writes performed by stdout are more.
So now if I make stdout... (0 Replies)
Discussion started by: sunilsbjoshi
0 Replies
4. HP-UX
Dear frnds,
i just migrated to hp_ux11i from digital unix, from my new system some printers not printing next day, what i mean is, in lpstat it shows printer is enabled but printing not happening. for that what i do u know, i just disable the lp and enable it again. then it would print. is there... (0 Replies)
Discussion started by: jestinabel
0 Replies
5. UNIX Desktop Questions & Answers
ie: man cat
....
- u The output is not buffered (3 Replies)
Discussion started by: Xcislav
3 Replies
6. Shell Programming and Scripting
Hi Guys,
My mail queue is showing a mail.
I want to flush the queue.
Can you let me know how to flush the mail queue.
Regards,
Magesh (12 Replies)
Discussion started by: mac4rfree
12 Replies
7. Shell Programming and Scripting
Hello Everybody,
thanks in advance for spending some time in my problem.
My problem is this:
I want to call a java-Programm out of my shell skript, check if die return code is right, and split the output to the normal output and into a file.
The following code doesn't work right, because in... (2 Replies)
Discussion started by: danifunny
2 Replies
8. Emergency UNIX and Linux Support
I have a Linux machine and it seems DNS cache is not getting clear on it. It is still showing old values, even after changing in DNS server by Network team. I did /etc/init.d/nscd restart But still it is showing old values on this server.
On my rest of servers in environment, nslookup is showing... (7 Replies)
Discussion started by: solaris_1977
7 Replies
9. UNIX for Beginners Questions & Answers
Input file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
LEARN ABOUT OPENSOLARIS
setlinebuf
setbuffer(3C) Standard C Library Functions setbuffer(3C)
NAME
setbuffer, setlinebuf - assign buffering to a stream
SYNOPSIS
#include <stdio.h>
void setbuffer(FILE *iop, char *abuf, size_t asize);
int setlinebuf(FILE *iop);
DESCRIPTION
The setbuffer() and setlinebuf() functions assign buffering to a stream. The three types of buffering available are unbuffered, block
buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as writ-
ten; when it is block buffered, many characters are saved and written as a block; when it is line buffered, characters are saved until
either a NEWLINE is encountered or input is read from stdin. The fflush(3C) function may be used to force the block out early. Normally all
files are block buffered. A buffer is obtained from malloc(3C) upon the first getc(3C) or putc(3C) performed on the file. If the standard
stream stdout refers to a terminal, it is line buffered. The standard stream stderr is unbuffered by default.
The setbuffer() function can be used after a stream iop has been opened but before it is read or written. It uses the character array abuf
whose size is determined by the asize argument instead of an automatically allocated buffer. If abuf is the null pointer, input/output
will be completely unbuffered. A manifest constant BUFSIZ, defined in the <stdio.h> header, tells how large an array is needed:
char buf[BUFSIZ];
The setlinebuf() function is used to change the buffering on a stream from block buffered or unbuffered to line buffered. Unlike set-
buffer(), it can be used at any time that the stream iop is active.
A stream can be changed from unbuffered or line buffered to block buffered by using freopen(3C). A stream can be changed from block
buffered or line buffered to unbuffered by using freopen(3C) followed by setbuf(3C) with a buffer argument of NULL.
RETURN VALUES
The setlinebuf() function returns no useful value.
SEE ALSO
malloc(3C), fclose(3C), fopen(3C), fread(3C), getc(3C), printf(3C), putc(3C), puts(3C), setbuf(3C), setvbuf(3C)
NOTES
A common source of error is allocating buffer space as an "automatic" variable in a code block, and then failing to close the stream in the
same block.
SunOS 5.11 13 May 1997 setbuffer(3C)