100 lines
3.2 KiB
Groff
100 lines
3.2 KiB
Groff
'\"macro stdmacro
|
|
.if n .pH 2/gen/close @(#)close 43.5 of 8/4/92
|
|
.\" Copyright 1992, 1991 UNIX System Laboratories, Inc.
|
|
.\" Copyright 1990, 1989 AT&T
|
|
.TH close 2
|
|
.SH NAME
|
|
\f4close\f1 \- close a file descriptor
|
|
.SH SYNOPSIS
|
|
\f4#include <unistd.h>\f1
|
|
.br
|
|
\f4int close(int \f2fildes\fP);\f1
|
|
.SH DESCRIPTION
|
|
.I fildes\^
|
|
is a
|
|
file descriptor
|
|
obtained from a
|
|
\f4creat\fP,
|
|
\f4open\fP,
|
|
\f4dup\fP,
|
|
\f4fcntl\fP,
|
|
\f4pipe\fP,
|
|
or
|
|
\f4iocntl\fP
|
|
system call.
|
|
\f4close\fP
|
|
closes the file descriptor indicated by \f2fildes\fP.
|
|
All outstanding record locks owned by the process (on the file indicated by
|
|
\f2fildes\fP) are removed.
|
|
.PP
|
|
If the link count of the file is zero, when all file descriptors
|
|
associated with the file have been closed, the space occupied by the
|
|
file is freed and the file is no longer accessible.
|
|
.PP
|
|
If a \s-1STREAMS\s0-based
|
|
[see \f4intro\fP(2)] \f2fildes\fP is closed,
|
|
and the calling process had previously registered to receive
|
|
a \f4SIGPOLL\fP signal [see \f4signal\fP(5)] for
|
|
events associated with that stream [see \f4I_SETSIG\fP in \f4streamio\fP(7)],
|
|
the calling process will be unregistered for events associated with the stream.
|
|
The last \f4close\fP for a stream causes the stream associated with
|
|
\f2fildes\f1 to be dismantled.
|
|
If
|
|
\f4O_NDELAY\fP and \f4O_NONBLOCK\fP
|
|
are clear and there have been no signals posted for the stream,
|
|
and if there are data on the module's write queue,
|
|
\f4close\fP
|
|
waits up to 15 seconds (for each module and driver) for any output to drain
|
|
before dismantling the stream.
|
|
The time delay can be changed via an \f4I_SETCLTIME\f1 \f4ioctl\f1 request
|
|
[see \f4streamio\f1(7)].
|
|
If \f4O_NDELAY\fP or \f4O_NONBLOCK\fP is set,
|
|
or if there are any pending signals,
|
|
\f4close\fP does not wait for output to drain, and dismantles
|
|
the stream immediately.
|
|
.PP
|
|
If \f2fildes\fP is associated with one end of a pipe, the last \f4close\fP causes
|
|
a hangup to occur on the other end of the pipe.
|
|
In addition, if the other end of the pipe has been named [see \f4fattach\f1(3C)],
|
|
the last \f4close\fP forces the named end to be detached [see \f4fdetach\f1(3C)].
|
|
If the named end has no open processes associated with it and becomes detached,
|
|
the stream associated with that end is also dismantled.
|
|
.PP
|
|
When closing all (or most) of a process's open file descriptors, it is
|
|
best not to close all descriptors up to the system maximum, as this value
|
|
can be large. See \f4getdtablehi\fP(3C).
|
|
.PP
|
|
The named file is closed unless one or more of the following are true:
|
|
.TP 15
|
|
\f4EBADF\fP
|
|
.I fildes\^
|
|
is not a valid open
|
|
file descriptor.
|
|
.TP 15
|
|
\f4EINTR\fP
|
|
A signal was caught during the \f4close\fP system call.
|
|
.TP 15
|
|
\f4ETIMEDOUT\fP
|
|
The object of the close is located on a remote system which is not available [see \f4intro\fP(2)].
|
|
.PP
|
|
If the named file is a remote object accessed via NFS, \f4close\fP may return
|
|
errors from a buffered \f4write\fP call.
|
|
.SH "SEE ALSO"
|
|
\f4creat\fP(2),
|
|
\f4dup\fP(2),
|
|
\f4exec\fP(2),
|
|
\f4fattach\f1(3C),
|
|
\f4fcntl\fP(2),
|
|
\f4fdetach\fP(3C),
|
|
\f4getdtablehi\fP(3C),
|
|
\f4intro\fP(2),
|
|
\f4open\fP(2),
|
|
\f4pipe\fP(2),
|
|
\f4signal\fP(2),
|
|
\f4signal\fP(5),
|
|
\f4streamio\fP(7)
|
|
.SH "DIAGNOSTICS"
|
|
Upon successful completion, a value of 0 is returned.
|
|
Otherwise, a value of \-1 is returned and \f4errno\fP
|
|
is set to indicate the error.
|