If the assignment statement completes before the next

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ion after calling dup2(4,1). Both descriptors now correspond to file , file has been closed, and the reference count for file has been incremented. From this point on, any data that is written to standard output is redirected to file . per process descriptor table 0 1 2 3 4 5 6 7 open file table entries file B file pos refcnt = 2 ... i-node table entries file B ... st_mode st_size Figure 12.21: Kernel data structures after dup2(4,1) 12.4.6 The close Function A process informs the kernel that is finished reading and writing a file by calling the close function. #include <unistd.h> int close(int fd); returns: zero if OK, -1 on error The kernel does not delete the associated file table entry unless the reference count is zero. For example, 628 CHAPTER 12. NETWORK PROGRAMMING suppose we have the situation in Figure 12.21, where descriptors 1 and 4 both point to the same file table entry. If we were to close descriptor 1, then we could still perform input and output on descriptor 4. Closing a closed descriptor is an error,...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online