Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

fcntl(2)

lockf(3)

open(2)

open(2)

pipe(2)

socket(2)

streamio(7)

close(2)  —  System Calls

OSF

NAME

close − Closes the file associated with a file descriptor

SYNOPSIS

int close (
int filedes );

PARAMETERS

filedesSpecifies a valid open file descriptor. 

DESCRIPTION

The close() function closes the file associated with the filedes parameter. 

All regions of a file specified by the filedes parameter that this process has previously locked with the lockf() function are unlocked. This occurs even if the process still has the file open by another file descriptor. 

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. 

When the close() function needs to block, only the calling thread is suspended rather than all threads in the calling process. 

The last close() for a stream causes the stream associated with fildes to be dismantled. Dismantling includes popping any modules on the stream and closing the driver.  If O_NDELAY and O_NONBLOCK are clear and there are no signals posted for the stream, close() waits up to 15 seconds for each module to drain and up to 15 seconds for each driver to drain.  If the O_NDELAY or the O_NONBLOCK flag is set or if there are any pending signals, close() does not wait for output to drain, and dismantles the stream immediately.  If a STREAMS file is closed, and the calling process had previously registered to receive a SIGPOLL signal [see signal()] for events associated with that file [see I_SETSIG in streamio(7)], the calling process is unregistered for events associated with the file. 

NOTES

AES Support Level:
Full use

RETURN VALUES

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

ERRORS

If the close() function fails, errno may be set to one of the following values:

[EBADF]The filedes parameter is not a valid open file descriptor. 

[EINTR]The close() function was interrupted by a signal which was caught. 

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

RELATED INFORMATION

Functions: exec(2), fcntl(2), lockf(3), open(2), open(2), pipe(2), socket(2), streamio(7)

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