|
|
1.1 root 1: .TH CLOSE 2 "27 July 1983"
2: .UC 4
3: .SH NAME
4: close \- delete a descriptor
5: .SH SYNOPSIS
6: .B close(d)
7: .br
8: .B "int d;"
9: .SH DESCRIPTION
10: The
11: \fIclose\fP call deletes a descriptor from the per-process object
12: reference table.
13: If this is the last reference to the underlying object, then
14: it will be deactivated.
15: For example, on the last close of a file
16: the current \fIseek\fP pointer associated with the file is lost;
17: on the last close of a
18: .IR socket (2)
19: associated naming information and queued data are discarded;
20: on the last close of a file holding an advisory lock
21: the lock is released; see further
22: .IR flock (2).
23: .PP
24: A close of all of a process's descriptors is automatic on
25: .IR exit ,
26: but since
27: there is a limit on the number of active descriptors per process,
28: .I close
29: is necessary for programs which deal with many descriptors.
30: .PP
31: When a process forks (see
32: .IR fork (2)),
33: all descriptors for the new child process reference the same
34: objects as they did in the parent before the fork.
35: If a new process is then to be run using
36: .IR execve (2),
37: the process would normally inherit these descriptors. Most
38: of the descriptors can be rearranged with
39: .IR dup2 (2)
40: or deleted with
41: .I close
42: before the
43: .I execve
44: is attempted, but if some of these descriptors will still
45: be needed if the execve fails, it is necessary to arrange for them
46: to be closed if the execve succeeds.
47: For this reason, the call ``fcntl(d, F_SETFD, 1)'' is provided
48: which arranges that a descriptor will be closed after a successful
49: execve; the call ``fcntl(d, F_SETFD, 0)'' restores the default,
50: which is to not close the descriptor.
51: .SH "RETURN VALUE
52: Upon successful completion, a value of 0 is returned.
53: Otherwise, a value of \-1 is returned and the global integer variable
54: .I errno
55: is set to indicate the error.
56: .SH ERRORS
57: .I Close
58: will fail if:
59: .TP 15
60: [EBADF]
61: \fID\fP is not an active descriptor.
62: .SH "SEE ALSO"
63: accept(2), flock(2), open(2), pipe(2), socket(2), socketpair(2),
64: execve(2), fcntl(2)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.