close
close is an operation that releases a file descriptor so its number can be allocated again.
A zero return does not establish file durability. Check close errors as well as the preceding writes and synchronization: delayed write errors can surface at close. [1]
Linux releases a valid descriptor before later close processing can fail; retrying the same number can therefore close an unrelated file that reused it. EBADF instead means the descriptor was invalid. This release order is visible in the v6.12 syscall. [3]
POSIX.1-2024 differs from Linux for EINTR: where that error is permitted, the descriptor remains open, whereas EINPROGRESS means it was closed with completion continuing asynchronously. For the descriptor left open after EINTR, POSIX leaves it unspecified whether calls other than close or posix_close can use it without error. Linux also releases the descriptor on EINTR. Recovery code must follow its target platform's contract. [2] [1]
Relations
- related
- file-descriptor, open-file-description, fsync, fdatasync, writeback-error
Limitations
- Descriptor release does not prove that earlier writes survived a failure.
- Closing a descriptor is not a general cancellation mechanism for another thread's I/O.
Citations
- Linux man-pages 6.19: close(2)
- POSIX.1-2024: close(), DESCRIPTION and RATIONALE
- Linux v6.12: close syscall releases the descriptor before flushing