Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ close(2) — SunOS 4.0.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

accept(2)

dup(2)

execve(2)

fcntl(2V)

flock(2)

intro(2)

open(2V)

pipe(2)

sigvec(2)

socket(2)

socketpair(2)

streamio(4)

CLOSE(2)  —  SYSTEM CALLS

NAME

close − delete a descriptor

SYNOPSIS

int close (des)
int des;

DESCRIPTION

The close() call deletes a descriptor from the per-process object reference table.  If this is the last reference to the underlying object, then it will be deactivated.  For example, on the last close of a file the current seek pointer associated with the file is lost; on the last close of a socket(2) associated naming information and queued data are discarded; on the last close of a file holding an advisory lock the lock is released (see flock(2) for further information).  close() does not, however, unmap memory mapped to a descriptor (see mmap(2), munmap(2)). 

A close of all of a process’s descriptors is automatic on exit, but since there is a limit on the number of active descriptors per process, close() is necessary for programs that deal with many descriptors. 

When a process forks (see fork(2)), all descriptors for the new child process reference the same objects as they did in the parent before the fork.  If a new process is then to be run using execve(2), the process would normally inherit these descriptors.  Most of the descriptors can be rearranged with dup(2) or deleted with close() before the execve() is attempted, but if some of these descriptors will still be needed if the execve() fails, it is necessary to arrange for them to be closed if the execve() succeeds.  The fcntl(2V) operation F_SETFD can be used to arrange that a descriptor will be closed after a successful execve, or to restore the default behavior, which is to not close the descriptor. 

If a STREAMS (see intro(2)) file is closed, and the calling process had previously registered to receive a SIGPOLL signal (see sigvec(2)) for events associated with that file (see I_SETSIG in streamio(4)), the calling process will be unregistered for events associated with the file.  The last close() for a stream causes that stream to be dismantled.  If the descriptor is not marked for no-delay mode 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 descriptor is marked for no-delay mode or if there are any pending signals, close() does not wait for output to drain, and dismantles the stream immediately. 

RETURN VALUE

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

ERRORS

close() will fail if:

EBADF des is not an active descriptor. 

EINTR A signal was caught before the close completed. 

SEE ALSO

accept(2), dup(2), execve(2), fcntl(2V), flock(2), intro(2), open(2V), pipe(2), sigvec(2), socket(2), socketpair(2), streamio(4)

Sun Release 4.0  —  Last change: 22 March 1989

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