[英]How can we limit file descriptor to always be less than 1024?
select 系統調用有一個限制,它不能超過 1024。這是文檔所說的
WARNING: select() can monitor only file descriptors numbers that
are less than FD_SETSIZE (1024)—an unreasonably low limit for
many modern applications—and this limitation will not change.
All modern applications should instead use poll(2) or epoll(7),
which do not suffer this limitation.
我們僅在 AWS EC2 實例中遇到過這種行為。 AWS fd 之外始終是您可以將其添加到問題中
Linux 系統 (Suse Linux 15 SP2) 中是否存在始終創建 fds < 1024 的設置?
你不想這樣做。 Linux 總是使用盡可能低的文件描述符。 因此,如果您獲得文件描述符 1024,則意味着文件描述符 0 到 1023 都已被使用。
如果你讓 Linux 只使用 0-1023 的文件描述符,那么你的程序仍然無法運行,因為不是獲取文件描述符 1024,你會得到一個錯誤,說它沒有更多的文件描述符可以使用。
你應該:
poll
而不是select
,就像文檔說的那樣。 這不是一個困難的改變。epoll
,當您同時輪詢大量文件描述符時,它比select
更有效。 然而,它要復雜得多。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.