close(2) System Calls Manual close(2) close - C (libc, -lc) #include int close(int fd); close() , . ( fcntl(2)), , , , . . fcntl(2) , (, ) . fd , ( open(2), , , ; , unlink(2), . close() 0. -1, errno . EBADF fd . EINTR close() ; signal(7). EIO -. ENOSPC EDQUOT NFS , , , , write(), fsync(2) close(). See CAVEATS for a discussion of why close() should not be retried after an error. POSIX.1-2008. 4.3BSD, SVr4, POSIX.1-1988. close-on-exec , execve(2). fcntl(2). CAVEATS , , . , . , fsync(2) ( ). close() , . , , . , , : (1) - . , write(2) () , , read(2) () , . (2) . . , , . Linux (, , ) : - - ( open(2) ). , close() . , close() close() , , write(2) close(), . silent () . NFS . , (. . , , , - -) (, , ). close() , . - , Linux always , . , , , . Many other implementations similarly always close the file descriptor (except in the case of EBADF, meaning that the file descriptor was invalid) even if they subsequently report an error on return from close(). POSIX.1-2008 was silent on this point. , -, close() fsync(2). The EINTR error is a somewhat special case. Regarding the EINTR error, POSIX.1-2008 said: If close() is interrupted by a signal that is to be caught, it shall return -1 with errno set to EINTR and the state of fd is unspecified. This permits the behavior that occurs on Linux and many other implementations, where, as with other errors that may be reported by close(), the file descriptor is guaranteed to be closed. However, it also permits another possibility: that the implementation returns an EINTR error and keeps the file descriptor open. (According to its documentation, HP-UX's close() does this.) The caller must then once more use close() to close the file descriptor, to avoid file descriptor leaks. This divergence in implementation behaviors provides a difficult hurdle for portable applications, since on many implementations, close() must not be called again after an EINTR error, and on at least one, close() must be called again. POSIX.1-2024 standardized the behavior of HP-UX, making Linux and many other implementations non-conforming. There are no plans to change the behavior on Linux. close_range(2), fcntl(2), fsync(2), open(2), shutdown(2), unlink(2), fclose(3) () Dmitry Bolkhovskikh , Yuri Kozlov Aleksandr Felda ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () . Linux man-pages 6.18 8 2026 . close(2)