1CLOSE(2)                   Linux Programmer's Manual                  CLOSE(2)
2
3
4

NAME

6       close - close a file descriptor
7

SYNOPSIS

9       #include <unistd.h>
10
11       int close(int fd);
12

DESCRIPTION

14       close()  closes  a  file descriptor, so that it no longer refers to any
15       file and may be reused.  Any record locks (see fcntl(2))  held  on  the
16       file  it  was  associated  with,  and owned by the process, are removed
17       (regardless of the file descriptor that was used to obtain the lock).
18
19       If fd is the last copy of a particular file  descriptor  the  resources
20       associated  with it are freed; if the descriptor was the last reference
21       to a file which has been removed using unlink(2) the file is deleted.
22

RETURN VALUE

24       close() returns zero on success.  On error, -1 is returned,  and  errno
25       is set appropriately.
26

ERRORS

28       EBADF  fd isn't a valid open file descriptor.
29
30       EINTR  The close() call was interrupted by a signal.
31
32       EIO    An I/O error occurred.
33

CONFORMING TO

35       SVr4, 4.3BSD, POSIX.1-2001.
36

NOTES

38       Not  checking  the return value of close() is a common but nevertheless
39       serious programming error.  It is quite possible that errors on a  pre‐
40       vious  write(2) operation are first reported at the final close().  Not
41       checking the return value when closing the file may lead to silent loss
42       of data.  This can especially be observed with NFS and with disk quota.
43
44       A  successful  close does not guarantee that the data has been success‐
45       fully saved to disk, as the kernel defers writes. It is not common  for
46       a  filesystem  to  flush  the buffers when the stream is closed. If you
47       need to be sure that the data is physically stored use  fsync(2).   (It
48       will depend on the disk hardware at this point.)
49

SEE ALSO

51       fcntl(2), fsync(2), open(2), shutdown(2), unlink(2), fclose(3)
52
53
54
55                                  2001-12-13                          CLOSE(2)
Impressum