gpt4 book ai didi

c - 关闭套接字的问题

转载 作者:太空宇宙 更新时间:2023-11-04 07:42:23 25 4
gpt4 key购买 nike

我正在尝试使用线程编写客户端/服务器程序。连接完成后我关闭套接字。服务器获得大量新连接,套接字编号(文件描述符)增加得非常快:运行 5 分钟后,我的文件描述符编号已经达到 800 左右!

这是正常现象吗?线程共享文件描述符吗?当我执行 close(sockfd); 时,数字是立即释放还是在一段时间后释放?

PS:我以前用fork(),没遇到过这个问题。谢谢

最佳答案

来自 pthreads(7):

POSIX.1 also requires that threads share a range of other attributes (i.e., these attributes are process-wide rather than per-thread):

  • open file descriptors

关于c - 关闭套接字的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2461164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com