Chinaunix首页 | 论坛 | 博客
  • 博客访问: 314389
  • 博文数量: 69
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 759
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-09 14:15
个人简介

〆 人生就是拼命地奔跑,和华丽的跌倒。 つ

文章分类

全部博文(69)

文章存档

2017年(2)

2016年(16)

2015年(21)

2014年(30)

分类: C/C++

2015-05-13 23:08:15

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()关闭一个文件的描述符,目的是不在查阅一些文件,可能重复利
       用。一些文件上被锁定的记录,与自身拥有进程和移动相关联(常常锁定
       有规则的文件描述符)。
      
       If fd is the last file descriptor referring to the underlying open file
       description  (see open(2)), the 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手册(2)),
        打开文件观察描述符的资源是自由的;如果描述符持续提及一个文件,
        那么这个文件已经使用unlink(2)移动删除了。

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是不合法的,无效的。

       EINTR  The close() call was interrupted by a signal; see signal(7).
        //EINTR close()通过一个标志被告知中断。

       EIO    An I/O error occurred.
      //EIO  输入/输出发生错误。

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 pre-
       vious 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()的返回值,不过程序错误是很严重的。最后close()的
        第一个报告就是一个错误完全可能阻止write()的运行。关闭文件的时候
        不检查返回值可能导致数据丢失。观察NFS和磁盘限额是很特别的。

       A  successful  close does not guarantee that the data has been success-
       fully 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.
      //他们通过系统在相同的进程中使用不同的线程去关闭文件描述符是不明智。
        一个文件描述符可能会重新利用,一些不知名的状况可能会某些方面造成
        无意识的影响。

       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 for-
       ever, 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.
      //当处理sockets的时候,你必须确信其他的路线上不是封闭的,否则,就会成
        为块永远,那么信息就不在通过socket发送。关闭socket之前要使用shutdown
        -(2)手册去关闭所有连接的部分。

     //Sockets是Windows下的规范,Windows Sockets是Windows下得到广泛应用的、开放的、支持多种协议的网络编程接口。

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) 
阅读(1930) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~