CLOSE(2) SysV CLOSE(2)
NAME
close - close a file descriptor
SYNOPSIS
int close (fildes)
int fildes;
DESCRIPTION
fildes is a file descriptor obtained from a creat, open, dup, fcntl, or
pipe 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.
When all file descriptors associated with a pipe or FIFO special file
have been closed, any data remaining in the pipe or FIFO is discarded.
When all file descriptors associated with an open file descriptor are
closed, the open file descriptor is freed. If the link count of the file
is 0 (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 (see intro(2)) file is closed, and the calling process had
previously registered to receive a SIGPOLL signal (see signal(2) and
sigset(2)) for events associated with that file (see I_SETSIG in
streamio(7)), the calling process will be unregistered for events
associated with the file. The last close for a Stream causes the Stream
associated with fildes to be dismantled. If O_NDELAY is not set and
there have been no signals posted for the Stream, close waits up to 15
seconds, for each module and driver, for any output to drain before
dismantling the Stream. If the O_NDELAY flag is set or if there are any
pending signals, close does not wait for output to drain and dismantles
the Stream immediately.
DIAGNOSTICS
A successful call returns 0. A failed call returns -1 and sets errno as
indicated under "Errors."
ERRORS
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.
SEE ALSO
creat(2), dup(2), exec(2), fcntl(2), intro(2), open(2), pipe(2),
signal(2), sigset(2).
streamio(7) in Domain/OS System Administration Reference.
NOTES
Under other implementations, close fails if the following is true:
[ENOLINK] fildes is on a remote machine and the link to that machine is
no longer active.