Seth Woolley's Man Viewer

Manual for close - man 2 close

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

CLOSE(2)                   Linux Programmer's Manual                  CLOSE(2)

       close(2,7,n) - close(2,7,n) a file(1,n) descriptor

       #include <unistd.h>

       int close(2,7,n)(int fd);

       close(2,7,n) closes a file(1,n) descriptor, so that it no longer refers to any file(1,n)
       and may be reused. Any locks held on the file(1,n) it was  associated  with,
       and  owned by the process, are removed (regardless of the file(1,n) descrip-
       tor that was used to obtain the lock).

       If fd is the last copy of a particular file(1,n)  descriptor  the  resources
       associated  with it are freed; if(3,n) the descriptor was the last reference
       to a file(1,n) which has been removed using unlink(1,2)(2) the file(1,n) is deleted.

       close(2,7,n) returns zero on success, or -1 if(3,n) an error(8,n) occurred.

       EBADF  fd isn't a valid open(2,3,n) file(1,n) descriptor.

       EINTR  The close(2,7,n)() call was interrupted by a signal.

       EIO    An I/O error(8,n) occurred.

       SVr4, SVID, POSIX, X/OPEN, BSD 4.3.  SVr4 documents an additional  ENO-
       LINK error(8,n) condition.

       Not  checking  the  return  value of close(2,7,n) is a common but nevertheless
       serious programming error.  It is quite possible that errors on a  pre-
       vious  write(1,2)(2)  operation  are first reported at the final close(2,7,n).  Not
       checking the return value when closing the file(1,n) may lead to silent loss
       of data.  This can especially be observed with NFS and with disk quota.

       A successful close(2,7,n) does not guarantee that the data has  been  success-
       fully  saved to disk, as the kernel defers writes. It is not common for
       a filesystem to flush(8,n) the buffers when the stream  is  closed.  If  you
       need  to  be sure that the data is physically stored use fsync(2).  (It
       will depend on the disk hardware at this point.)

       fcntl(2), fsync(2), open(2,3,n)(2), shutdown(2,8)(2), unlink(1,2)(2), fclose(3)

                                  2001-12-13                          CLOSE(2)

References for this manual (incoming links)