close(2) SDK R4.11 close(2)
NAME
close - close an object associated with a file descriptor
SYNOPSIS
#include <unistd.h>
int close (fildes)
int fildes;
where:
fildes A valid, active file descriptor
DESCRIPTION
If fildes is a valid, active descriptor, close breaks the connection
between the descriptor indicated by fildes and the object to which it
refers. If fildes is the last descriptor that refers to an object
pointer, the object pointer is "closed" by invoking the type-specific
close operation.
Thus, the type manager is informed only of the last close operation
of an object pointer. These managers (and specifically, the device
driver close operations) should not expect to be invoked during each
close system call.
Upon completion of the close operation, fildes will be inactive.
Until fildes is reallocated, subsequent operations using fildes will
result in an EBADF error condition.
If a STREAMS-based fildes is closed, and the calling process had
previously registered to receive a SIGPOLL signal for events
associated with that stream in, 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 ONDELAY and ONONBLOCK 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 ISETCLTIME ioctl. If ONDELAY
or ONONBLOCK 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.
Objects are also subject to implicit close operations via the exit
and exec operations. When a process terminates, all active
descriptors are closed. When a process performs a successful exec
operation, all active descriptors with the `close-on-exec' attribute
are closed. These implicit close operations are equivalent to an
explicit close operation.
On each close of an object, all outstanding locks owned by the
calling process on the object are released.
ACCESS CONTROL
None.
RETURN VALUE
0 The object was successfully closed.
-1 An error occurred. errno is set to indicate the error.
DIAGNOSTICS
Errno may be set to one of the following error codes:
EBADF fildes is not a valid, active descriptor.
EINTR Close call was interrupted.
EIO An i/o error occurred while reading from or writing to the
file system. The fildes is inactived.
SEE ALSO
accept(2), creat(2), dup(2), exec(2), fcntl(2), open(2), pipe(2),
signal(2), sigset(2), socket(2), socketpair(2).
Licensed material--property of copyright holder(s)