CLOSE(2) Linux Programmer's Manual CLOSE(2)
NAME
LINUX教程?close - close a file descriptor
//關閉一個fd
SYNOPSIS
vim上翻頁,#include
int close(int fd);
DESCRIPTION
docker rmi,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
linux vi、descriptor that was used to obtain the lock).
//close()關閉一個fd,這樣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是使用unlink()打開的最后文件的fd,那么文件被刪除
RETURN VALUE
close() returns zero on success. On error, -1 is returned, and errno is set
appropriately.
//成功:0
//錯誤:-1
ERRORS
EBADF fd isn't a valid open file descriptor.
//fd不是一個有效的打開的fd
EINTR The close() call was interrupted by a signal; see signal(7).
//close()被信號中斷
EIO An I/O error occurred.
//發生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.)
//成功的關閉并不能保證數據成功的寫入磁盤,因為kernel會延遲寫入.當流關閉的時候文件系統沖洗緩存
//不是一個普遍的現象.如果你需要確認數據被物理的存儲你可以使用fsync().(這取決于在此點是的硬盤)
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 reused, there are some obscure race conditions that may cause
unintended side effects.
//當在同一進程的不同線程中系統調用fd的時候就關閉fd可能是不明智的.因為fd可以被再使用,
//有一些模糊的競態條件可能會導致無意識的作用.
SEE ALSO
COLOPHON
This page is part of release 3.29 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can be found
at http://www.kernel.org/doc/man-pages/.
Linux 2007-12-28 CLOSE(2)
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态