This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ion after calling dup2(4,1). Both descriptors now correspond to ﬁle , ﬁle has been closed, and the reference count for ﬁle has been incremented. From this point on, any data that is written to standard output is redirected to ﬁle .
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 ﬁnished reading and writing a ﬁle 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 ﬁle 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 ﬁle 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.
- Spring '10
- The American