encyclopegia.org

Close (system call)

A close system call is a system call used to close a file descriptor by the kernel.[src] For most file systems, a program terminates access to a file in a filesystem using the close system call.[src] This flushes file buffers, updates file metadata, which may include and end-of-file indicator in the data; de-allocates resources associated with the file (including the file descriptor) and updates the system wide table of files in use.[src] Some programming languages maintain a data structure of files opened by their runtime library and may close when the program terminates.[src] This practice is known as resource acquisition is initialization (RAII).[src] Some operating systems will invoke close on files held by a program if it terminates.[src] Some operating systems will invoke the close syscall as part of an operating system recovery as a result of a system failure.[src]

A close system call is a system call used to close a file descriptor by the kernel.[src] For most file systems, a program terminates access to a file in a filesystem using the close system call.[src] This flushes file buffers, updates file metadata, which may include and end-of-file indicator in the data; de-allocates resources associated with the file (including the file descriptor) and updates the system wide table of files in use.[src] Some programming languages maintain a data structure of files opened by their runtime library and may close when the program terminates.[src] This practice is known as resource acquisition is initialization (RAII).[src] Some operating systems will invoke close on files held by a program if it terminates.[src] Some operating systems will invoke the close syscall as part of an operating system recovery as a result of a system failure.[src] ==C interfaces== ===Standard library=== The C standard library provides the fclose function with the signature int fclose(FILE* stream); The file is represented by the file pointer stream , which is typically an abstraction over a platform-dependent handle to the underlying file object.[src] As such, fclose is almost always implemented as a library call which in turn closes the file with the corresponding system call.[src] This additional layer of abstraction allows the function to remain portable across different environments while providing the same functionality.[src] A successful call to fclose returns zero, but if an error occurs the function instead returns EOF (commonly defined as -1).[src] In both cases, the file pointer is guaranteed to be disassociated from the file and should not be further used by an application.[src] ===POSIX=== The POSIX standard includes the close system call, declared as int close(int fildes); The function takes the file descriptor fildes , an integer identifier for the open file, as a parameter.[src] It allows the value of fildes to be reused for later opened files, and if no other file descriptor currently refers to the same file, any resources associated with the open file are freed.[src] On success, close returns zero.[src] Otherwise if an error occurs, the function returns -1 and assigns a relevant error code to the global variable errno .[src] In this situation, the value of errno and the state of fildes are partially dependent on the version of POSIX the system adheres to.[src] In all versions of POSIX, errno is set to EBADF if fildes is an invalid file descriptor.[src] And from POSIX.1-2001 onwards, to EIO if a platform-dependent IO error occurs.[src] Up to and including POSIX.1-2017, if a signal is sent to the process and interrupts the call to close , the call fails with EINTR and the state of the file descriptor is explicitly unspecified by the standard.[src] So depending on the implementation, the file descriptor may have been closed, in which case close should not be called again.[src] Or the file descriptor may still remain open, meaning close should be called again.[src] This behaviour was argued by developers to be unsafe for portable applications.[src] In particular, it can cause race conditions in multithreaded environments, where a file descriptor may be reused in a different thread prior to retrying close .[src] To address this, POSIX.1-2024 instead requires that in the event of an interrupted call to close , the function can either succeed, fail with EINTR and leave the file descriptor open, or fail with EINPROGRESS and close the file descriptor.[src] ==References== ==External links==[src]

33 sentences · 33 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Close (system call)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/close-system-call. Accessed 02 December 2026.

Chicago

"Close (system call)." encyclopegia.org. Accessed December 2, 2026. https://encyclopegia.org/wiki/close-system-call.

APA

encyclopegia.org. (2026). Close (system call). Retrieved December 2, 2026, from https://encyclopegia.org/wiki/close-system-call

Accessed December 2, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Applicant Tracking System

article · references available

Solar System

stub · references available

binary numeral system

stub · references available

calendar system

stub · references available

centimeter–gram–second system of units

stub · references available

judicial system of Ukraine

stub · references available

Mac operating system

stub · references available

Public distribution system

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1349715565 · 0.5 · snapshot enwiki-001349715565

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners
  • Index — every corpus, paper and record
  • Estate guide — what a public data estate is
  • Founder — Lois-Kleinner Alpasan
  • Records — DOIs and external deposits
  • Documents — one-pagers, PDFs and QR codes
  • Brand kit — logos and share images
  • Papers — plain-language briefs with citations
  • Browser — search engine, PWA and bookmarklet
  • Anticloud — the operator and its projects

As seen in Business Insider · 336 outlets · evidence DOIs · plain-language papers

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.