Chinaunix首页 | 论坛 | 博客
  • 博客访问: 204271
  • 博文数量: 28
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 386
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-09 14:15
文章分类

全部博文(28)

文章存档

2015年(12)

2014年(16)

分类: LINUX

2015-05-19 22:48:58

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


NAME
       close - close a file descriptor


SYNOPSIS
       #include


       int close(int fd);


DESCRIPTION
       close() closes a file descriptor, so that it no longer refers to any file and may be reused.  Any record locks (see fcntl(2)) held on the
 file it was associated with, and owned自备 by the process进程, are removed (regardless of the file descriptor that was used to obtain the  lock).
        //close()函数是关闭fd,以至于它不再指向任何文件也可能被重复使用。任何对文件抓紧不放的记录都是由联系的,被进程所有,被移           //除(无论fd被用来获取这个锁)


       If fd is the last file descriptor referring to the underlying open file description (see open(2)), the resources associated with the open
 file description are freed; if the descriptor was the last reference to a file which  has  been  removed  using  unlink(2)  the  file  is deleted.
       //如果fd是open()打开的最后一个fd,那么与打开的fd有关的资源就会被释放;如果fd是unlink()打开的最后一个fd,那么文件就会被删            //除。


RETURN VALUE
       close() returns zero on success.  On error, -1 is returned, and errno is set appropriately.
       //close()函数如果成功返回0.如果错误返回-1。
ERRORS
       EBADF  fd isn’t a valid open file descriptor.
       //EBADF fd不是一个有效的fd.


       EINTR  The close() call was interrupted by a signal; see signal(7).
       //EINTR close() 产生一个错误信号。


       EIO    An I/O error occurred.
       //EIO  I/O口发生错误。


CONFORMING TO
       SVr4, 4.3BSD, POSIX.1-2001.


NOTES
       Not  checking  the return value of close() is a common but nevertheless serious programming error.  It is quite possible that errors on a previous write(2) operation are first reported at the final close().  Not checking the return value when closing the  file  may  lead  to
 silent loss of data.  This can especially be observed with NFS and with disk quota.
       //通常不会检查close()函数的返回值,尽管如此一些程序也会产生错误。这个错误有可能在之前的write()中,而在后面的close()中被           //报告出来。不检查
      // 返回值可能会导致文件数据安静的丢失,不要渐染返回值。


       A  successful  close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes.  It is not common for a file system to flush 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.)
        //关闭文件成功也不能保证数据就会被写入硬盘中,因为内核会暂缓写入。不是所有的文件系统在关闭文件时就会刷新缓冲区。如果           //你想确定数据是否被写
        //入物理内存可以用fsync(2)来确定。(这取决于硬盘在这个点上)


       It  is  probably unwise to close file descriptors while they may be in use by system calls in other threads in the same process.  Since a file descriptor may be re-used, there are some obscure race conditions that may cause unintended side effects.
       //当fd在同一进程的不同线程中被调用时关闭fd是不明智的。因为fd可以被重复利用,一些模糊的竞赛状态可能会无意间使用。


       When dealing with sockets, you have to be sure that there is no recv(2) still blocking on it on another thread, otherwise it might  block forever,  since  no  more  messages  will be sent via the socket. Be sure to use shutdown(2) to shut down all parts the connection before closing the socket.
        //当你处理接口时,你必须确定其他进程接受状态是关闭的,不然没有信息发送到接口导致永远锁住。确保关闭接口之前关闭所有有           //关系的数据库。


SEE ALSO
       fcntl(2), fsync(2), open(2), shutdown(2), unlink(2), fclose(3)


COLOPHON
       This page is part of release 3.22 of the Linux man-pages project.  A description of the project, and information  about  reporting  bugs,can be found at
        //这篇是linux3.22手册项目中的一部分,一个文件的描述符,还有关于漏洞
        // 信息的报告,会在中找到。




Linux                             2007-12-28                          CLOSE(2)
(END) 

阅读(4476) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~