I think I am not clear about when and how read/write blocks for various kind of files.
(disk file, pipe, socket, FIFO)
Could any one explain for both read and write scenarios of each file type?
Thanks!!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For a disk-based file,
readandwritemay block briefly while the requested read/write is performed. Areadat the end of a file will always return a short result, and awriteto a file on a full FS will fail — barring various unusual circumstances,read/writeto a plain file will never block indefinitely.For pipes, sockets, and FIFOs,
readwill block if no data is available, andwritewill block if the pipe/socket/FIFO is “full” (e.g, you’ve written a bunch of data and the process on the other end hasn’t read it yet). The exact amount of data required to fill the buffer is variable; for a pipe, for instance, it’s typically between 4 and 64 kB.