close(2) close(2)
close - close a file descriptor
#include <unistd.h>
int close(int fildes<b>);
fildes is a file descriptor obtained from a creat, open, dup, fcntl,
pipe, or iocntl system call. close closes the file descriptor indicated
by fildes. All outstanding record locks owned by the process (on the
file indicated by fildes) are removed.
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.
If a STREAMS-based [see intro(2)] fildes is closed, and the calling
process had previously registered to receive a SIGPOLL signal [see
signal(5)] for events associated with that stream [see I_SETSIG in
streamio(7)], the calling process will be unregistered for events
associated with the stream. The last close for a stream causes the
stream associated with fildes to be dismantled. If O_NDELAY and
O_NONBLOCK are clear and there have been no signals posted for the
stream, and if there are data on the module's write queue, close 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 I_SETCLTIME
ioctl request [see streamio(7)]. If O_NDELAY or O_NONBLOCK is set, or if
there are any pending signals, close does not wait for output to drain,
and dismantles the stream immediately.
If fildes is associated with one end of a pipe, the last close 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 fattach(3C)], the last close forces
the named end to be detached [see fdetach(3C)]. If the named end has no
open processes associated with it and becomes detached, the stream
associated with that end is also dismantled.
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 getdtablehi(3C).
The named file is closed unless one or more of the following are true:
EBADF fildes is not a valid open file descriptor.
EINTR A signal was caught during the close system call.
ETIMEDOUT The object of the close is located on a remote system
which is not available [see intro(2)].
Page 1
close(2) close(2)
If the named file is a remote object accessed via NFS, close may return
errors from a buffered write call.
creat(2), dup(2), exec(2), fattach(3C), fcntl(2), fdetach(3C),
getdtablehi(3C), intro(2), open(2), pipe(2), signal(2), signal(5),
streamio(7)
Upon successful completion, a value of 0 is returned. Otherwise, a value
of -1 is returned and errno is set to indicate the error.
PPPPaaaaggggeeee 2222 [ Back ]
|