A close system call is a
system call
In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
used to close a
file descriptor
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically h ...
by the
kernel. For most
file systems, a
program terminates access to a
file in a filesystem using the close system call. This flushes file buffers, updates file
metadata
Metadata (or metainformation) is "data that provides information about other data", but not the content of the data itself, such as the text of a message or the image itself. There are many distinct types of metadata, including:
* Descriptive ...
, which may include and
end-of-file indicator in the data; de-allocates resources associated with the file (including the
file descriptor
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically h ...
) and updates the system wide table of files in use. Some
programming languages
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their syntax (form) and semantics (meaning), usually defined by a formal language. Languages usually provide features ...
maintain a
data structure
In computer science, a data structure is a data organization and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the relationships amo ...
of files opened by their
runtime library
A runtime library is a library that provides access to the runtime environment that is available to a computer program tailored to the host platform. A runtime environment implements the execution model as required for a development environme ...
and may close when the program terminates. This practice is known as
resource acquisition is initialization (RAII). Some operating systems will invoke the
close
on files held by a program if it terminates. Some operating systems will invoke the
close
syscall as part of an operating system recovery as a result of a system failure.
C library POSIX definition
The
closecall is standardized by the
POSIX
The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
specification
int close (int filedes);
int fclose (FILE *stream);
The function returns zero to indicate the file was closed successfully. If any error occurs, a value of -1 is returned and errno is appropriately set.
The errors that can occur include:
;
: The argument supplied was not a valid file descriptor
;
: The function call was interrupted by a
signal
A signal is both the process and the result of transmission of data over some media accomplished by embedding some variation. Signals are important in multiple subject fields including signal processing, information theory and biology.
In ...
;
: An
I/O error occurred
References
POSIX close
External links
*
{{Computer files
C POSIX library
System calls