加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

unix – TIME_WAIT使用文件描述符?

发布时间:2020-12-15 18:35:38 所属栏目:安全 来源:网络整理
导读:在许多TCPIP和Web调整指南中,建议增加文件描述符的最大数量 收到错误“太多打开的文件”时 但是,我在“lsof -i”的输出中看不到TIME_WAIT 有谁知道TIME_WAIT消耗文件描述符?或不 应用程序使用文件描述符从套接字读取/写入.因此,如果应用程序调用close(),则
在许多TCPIP和Web调整指南中,建议增加文件描述符的最大数量
收到错误“太多打开的文件”时

但是,我在“lsof -i”的输出中看不到TIME_WAIT

有谁知道TIME_WAIT消耗文件描述符?或不

应用程序使用文件描述符从套接字读取/写入.因此,如果应用程序调用close(),则立即释放文件描述符.

另一方面,如果应用程序调用shutdown(),文件描述符将保持有效,以便应用程序仍然可以从/向套接字读/写.

https://oroboro.com/file-handle-leaks-server/行情:

Myth: Sockets in TCP TIME_WAIT are holding file handles Hostage

When you close a TCP/IP socket the operating system does not release the socket right away. For complex reasons,the socket structure must be kept out of circulation for a few minutes because there is a small chance that an IP packet may arrive on that socket after it has been closed. If the operating system re-used the socket then the new user of that connection would have their session affected by someone else’s lost packets.

But this does not hold a file handle open. When you close the socket’s file descriptor,the file descriptor itself is closed. You will not get the “Too many files open” error. If you have too many sockets open,then your server may stop accepting new connections. There are ways to deal with that ( allowing sockets to be re-used,or lowering TCP TIME_WAIT )- but raising the file handle limit isn’t one of them.

Myth: It takes time for file handles to be released

This is related to the TCP TIME_WAIT myth. The mistaken belief that when you close a file handle that you must wait some time for the operating system to release the handle.

Closing a file handle will call into whatever os method releases the resource,and the OS will release that resource either immediately,or sometimes later as in the case with sockets,but close() will release the file handle in the file handle table immediately. Your process is in complete control of its file handle table,and doesn’t need to wait for anything to free a slot in its own file descriptor table.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读