Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

creat(2)

dup(2)

exec(2)

fcntl(2)

getsockopt(2)

intro(2)

open(2)

pipe(2)

setsockopt(2)

signal(2)

sigset(2)

sockio(7)

streamio(7)

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.

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. 

If fildes refers to a socket which promises reliable delivery of data and SO_LINGER is set, the close attempt will be blocked until it is able to transmit the data or until it decides it is unable to deliver the information.  If SO_LINGER is disabled, the close will be processed in a manner that allows it to continue as quickly as possible. 

When there is an outstanding cancelable asynchronous I/O operation against fildes when close() is called, that I/O operation may be cancelled.  An outstanding request will be cancelled if the actual I/O operation has not occured. Otherwise, it is allowed to go through I/O completion. However, on close() all signals to the process are disabled, which means any signal generated because of the I/O completion will not affect the process.  An I/O operation which is not cancelled completes as if the close() operation had not yet occurred. 

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. 

­[ENOLINK] Fildes is on a remote machine and the link to that machine is no longer ctive. 

RETURN VALUE

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

NOTE

This call is defined in the 88open Binary and Object Compatibility Standards (BCS/OCS) as well as their respective 88eopn Networking Supplements (BCSNS/OCSNS) for use in BCS/OCS compliant applications.  OCS/OCSNS-defined functions may be accessed by passing OCS options to cc(1) and ld(1). 

SEE ALSO

creat(2), dup(2), exec(2), fcntl(2), getsockopt(2), intro(2), open(2), pipe(2), setsockopt(2), signal(2), sigset(2), sockio(7), streamio(7). 

CX/UX Programmer’s Reference Manual

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