unix – TIME_WAIT使用文件描述符?

前端之家收集整理的这篇文章主要介绍了unix – TIME_WAIT使用文件描述符?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在许多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.

原文链接:https://www.f2er.com/bash/385705.html

猜你在找的Bash相关文章