Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ close(2) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

creat(2)

dup(2)

exec(2)

fcntl(2)

open(2)

pipe(2)

signal(2)

fattach(3C)

fdetach(3C)

unistd(4)

signal(5)

close(2)                                                           close(2)

NAME
     close - close a file descriptor

SYNOPSIS
     #include <unistd.h>

     int close (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 the open file description
     have been closed, the open file description is freed.

     If the link count of the file is zero, when all file descriptors asso-
     ciated with the file have been closed, the memory space occupied by
     the file is freed and the file is no longer accessible.

     If a STREAMS-based fildes is closed, and the calling process had pre-
     viously registered to receive a SIGPOLL signal [see signal(2) and sig-
     set(2)] for events associated with that stream [see ISETSIG 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 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 request [see streamio(7)]. 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.

     If fildes refers to the master side of a pseudo-terminal and this is
     the last close, a SIGHUP signal is sent to the process group, if any,
     for which the slave side of the pseudo-terminal is the controlling
     terminal. It is unspecified whether closing the master side of the
     pseudo-terminal flushes all queued input and output.

     If fildes refers to the slave side of a STREAMS-based pseudo-terminal,
     a zero-length message may be sent to the master.





Page 1                       Reliant UNIX 5.44                Printed 11/98

close(2)                                                           close(2)

ERRORS
     The following error code descriptions are function-specific. You will
     find a general description in introprm2(2) or in errno(5).

     The named file is closed unless one or more of the following apply:

     EBADF     fildes is not a valid open file descriptor.

     EINTR     A signal was caught during the close() system call.

     EIO       An I/O error occurred while reading from or writing to the
               file system.

     ENOLINK   fildes is on a remote machine and the link to that machine
               is no longer active.

RESULT
     Upon successful completion, a value of 0 is returned. Otherwise, a
     value of -1 is returned and errno is set to indicate the error.

SEE ALSO
     creat(2), dup(2), exec(2), fcntl(2), open(2), pipe(2), signal(2),
     fattach(3C), fdetach(3C), unistd(4), signal(5).































Page 2                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026