Why must flush all line-buffered output streams?


 
Thread Tools Search this Thread
Top Forums Programming Why must flush all line-buffered output streams?
# 1  
Old 03-27-2011
Question 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?
# 2  
Old 03-27-2011
What if you're using both ends of a pipe? If you write to one end and it ends up in a buffer, then you try to read it from the other end, it'll hang until something flushes it.
# 3  
Old 03-27-2011
The behavior mentioned in that Stevens quote exists in many c stdio implementations to ensure that prompts without a newline have been emitted before input is read. I don't believe that's standardized even though it's probably common behavior. It's best to use an explicit fflush as necessary.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

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

2. Emergency UNIX and Linux Support

DNS flush is not working

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

3. Shell Programming and Scripting

Problem with call of Java Programm & return code handling & output to several streams.

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

4. Shell Programming and Scripting

flush the mail queue

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

5. UNIX Desktop Questions & Answers

What is buffered output?

ie: man cat .... - u The output is not buffered (3 Replies)
Discussion started by: Xcislav
3 Replies

6. HP-UX

lp print flush

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

7. HP-UX

changing col(1) command stdout as fully buffered?

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

8. UNIX for Advanced & Expert Users

changing col(1) command stdout as fully buffered?

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

9. Shell Programming and Scripting

Help capturing and reformatting buffered and unbuffered output

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
Login or Register to Ask a Question