1 .\" Copyright (c) 1980 Regents of the University of California.
2 .\" All rights reserved. The Berkeley software License Agreement
3 .\" specifies the terms and conditions for redistribution.
5 .\" @(#)close.2 6.3 (Berkeley) 5/22/86
7 .TH CLOSE 2 "May 22, 1986"
10 close \- delete a descriptor
16 int close(int \fId\fP)
22 call deletes a descriptor from the per-process object
24 If this is the last reference to the underlying object, then
25 it will be deactivated.
26 For example, on the last close of a file
27 the current \fIseek\fP pointer associated with the file is lost;
28 on the last close of a TCP/IP descriptor
29 associated naming information and queued data are discarded;
30 on the last close of a file holding an advisory lock
31 the lock is released (see further
34 A close of all of a process's descriptors is automatic on
37 there is a limit on the number of active descriptors per process,
39 is necessary for programs that deal with many descriptors.
41 When a process forks (see
43 all descriptors for the new child process reference the same
44 objects as they did in the parent before the fork.
45 If a new process is then to be run using
47 the process would normally inherit these descriptors. Most
48 of the descriptors can be rearranged with
54 is attempted, but if some of these descriptors will still
57 fails, it is necessary to arrange for them to be closed if the
60 For this reason, the call ``fcntl(d, F_SETFD, \fIflags\fR)'' is provided,
61 that can be used to mark a descriptor "close on exec" by setting
67 fcntl(d, F_SETFD, fcntl(d, F_GETFD) | FD_CLOEXEC);
70 Upon successful completion, a value of 0 is returned.
71 Otherwise, a value of \-1 is returned and the global integer variable
73 is set to indicate the error.
79 \fID\fP is not an active descriptor.