linux系统文件关闭函数close,linux系统-C库函数--close中文翻译

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)

阅读(1244) | 评论(0) | 转发(0) |

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值