好的一天,我在C/C++中使用了TCP选择,服务器需要用一个进程来处理2500个连接,但是它总是连接到1020个客户端,然后连接失败(中止/缓冲器检测过低)。我想这是因为试图打开2500个文件描述符,BU。对于1020fd+主套接字+stdin/stdout/stderr,我达到了每个进程打开文件的默认限制(1024)。
我试图在debian的limits文件中更改每个进程打开的最大文件数,但似乎什么都没有发生,因为它在1020年之前仍然保持连接。
*** buffer overflow detected ***: ./WildChildrenServer terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x731ff)[0x7f08cb7a31ff]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7f08cb8264c7]
/lib/x86_64-linux-gnu/libc.so.6(+0xf46e0)[0x7f08cb8246e0]
/lib/x86_64-linux-gnu/libc.so.6(+0xf6437)[0x7f08cb826437]
./WildChildrenServer[0x405e4b]
./WildChildrenServer[0x40255d]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f08cb751b45]
./WildChildrenServer[0x402639]
======= Memory map: ========
00400000-00408000 r-xp 00000000 08:05 788806 /home/labam/Distribuidos/WildChildrenServer/bin/Release/WildChildrenServer
00607000-00608000 r--p 00007000 08:05 788806 /home/labam/Distribuidos/WildChildrenServer/bin/Release/WildChildrenServer
00608000-00609000 rw-p 00008000 08:05 788806 /home/labam/Distribuidos/WildChildrenServer/bin/Release/WildChildrenServer
00943000-009a2000 rw-p 00000000 00:00 0 [heap]
7f08c0000000-7f08c0021000 rw-p 00000000 00:00 0
7f08c0021000-7f08c4000000 ---p 00000000 00:00 0
7f08ca9a6000-7f08ca9b1000 r-xp 00000000 08:05 262665 /lib/x86_64-linux-gnu/libnss_files-2.19.so
7f08ca9b1000-7f08cabb0000 ---p 0000b000 08:05 262665 /lib/x86_64-linux-gnu/libnss_files-2.19.so
7f08cabb0000-7f08cabb1000 r--p 0000a000 08:05 262665 /lib/x86_64-linux-gnu/libnss_files-2.19.so
7f08cabb1000-7f08cabb2000 rw-p 0000b000 08:05 262665 /lib/x86_64-linux-gnu/libnss_files-2.19.so
7f08cabb2000-7f08cabb5000 r-xp 00000000 08:05 262663 /lib/x86_64-linux-gnu/libdl-2.19.so
7f08cabb5000-7f08cadb4000 ---p 00003000 08:05 262663 /lib/x86_64-linux-gnu/libdl-2.19.so
7f08cadb4000-7f08cadb5000 r--p 00002000 08:05 262663 /lib/x86_64-linux-gnu/libdl-2.19.so
7f08cadb5000-7f08cadb6000 rw-p 00003000 08:05 262663 /lib/x86_64-linux-gnu/libdl-2.19.so
7f08cadb6000-7f08cadd0000 r-xp 00000000 08:05 262756 /lib/x86_64-linux-gnu/libz.so.1.2.8
7f08cadd0000-7f08cafcf000 ---p 0001a000 08:05 262756 /lib/x86_64-linux-gnu/libz.so.1.2.8
7f08cafcf000-7f08cafd0000 r--p 00019000 08:05 262756 /lib/x86_64-linux-gnu/libz.so.1.2.8
7f08cafd0000-7f08cafd1000 rw-p 0001a000 08:05 262756 /lib/x86_64-linux-gnu/libz.so.1.2.8
7f08cafd1000-7f08cafe9000 r-xp 00000000 08:05 262671 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f08cafe9000-7f08cb1e8000 ---p 00018000 08:05 262671 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f08cb1e8000-7f08cb1e9000 r--p 00017000 08:05 262671 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f08cb1e9000-7f08cb1ea000 rw-p 00018000 08:05 262671 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f08cb1ea000-7f08cb1ee000 rw-p 00000000 00:00 0
7f08cb1ee000-7f08cb4a5000 r-xp 00000000 08:05 1053975 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
7f08cb4a5000-7f08cb6a5000 ---p 002b7000 08:05 1053975 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
7f08cb6a5000-7f08cb6ab000 r--p 002b7000 08:05 1053975 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
7f08cb6ab000-7f08cb72a000 rw-p 002bd000 08:05 1053975 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
7f08cb72a000-7f08cb730000 rw-p 00000000 00:00 0
7f08cb730000-7f08cb8cf000 r-xp 00000000 08:05 262678 /lib/x86_64-linux-gnu/libc-2.19.so
7f08cb8cf000-7f08cbacf000 ---p 0019f000 08:05 262678 /lib/x86_64-linux-gnu/libc-2.19.so
7f08cbacf000-7f08cbad3000 r--p 0019f000 08:05 262678 /lib/x86_64-linux-gnu/libc-2.19.so
7f08cbad3000-7f08cbad5000 rw-p 001a3000 08:05 262678 /lib/x86_64-linux-gnu/libc-2.19.so
7f08cbad5000-7f08cbad9000 rw-p 00000000 00:00 0
7f08cbad9000-7f08cbaef000 r-xp 00000000 08:05 262660 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f08cbaef000-7f08cbcee000 ---p 00016000 08:05 262660 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f08cbcee000-7f08cbcef000 rw-p 00015000 08:05 262660 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f08cbcef000-7f08cbdef000 r-xp 00000000 08:05 262677 /lib/x86_64-linux-gnu/libm-2.19.so
7f08cbdef000-7f08cbfee000 ---p 00100000 08:05 262677 /lib/x86_64-linux-gnu/libm-2.19.so
7f08cbfee000-7f08cbfef000 r--p 000ff000 08:05 262677 /lib/x86_64-linux-gnu/libm-2.19.so
7f08cbfef000-7f08cbff0000 rw-p 00100000 08:05 262677 /lib/x86_64-linux-gnu/libm-2.19.so
7f08cbff0000-7f08cc0dc000 r-xp 00000000 08:05 1055513 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20
7f08cc0dc000-7f08cc2dc000 ---p 000ec000 08:05 1055513 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20
7f08cc2dc000-7f08cc2e4000 r--p 000ec000 08:05 1055513 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20
7f08cc2e4000-7f08cc2e6000 rw-p 000f4000 08:05 1055513 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20
7f08cc2e6000-7f08cc2fb000 rw-p 00000000 00:00 0
7f08cc2fb000-7f08cc3fc000 r-xp 00000000 08:05 1057005 /usr/lib/libmysqlcppconn.so.7.1.1.3
7f08cc3fc000-7f08cc5fc000 ---p 00101000 08:05 1057005 /usr/lib/libmysqlcppconn.so.7.1.1.3
7f08cc5fc000-7f08cc60c000 rw-p 00101000 08:05 1057005 /usr/lib/libmysqlcppconn.so.7.1.1.3
7f08cc60c000-7f08cc62c000 r-xp 00000000 08:05 262661 /lib/x86_64-linux-gnu/ld-2.19.so
7f08cc80a000-7f08cc811000 rw-p 00000000 00:00 0
7f08cc828000-7f08cc82c000 rw-p 00000000 00:00 0
7f08cc82c000-7f08cc82d000 r--p 00020000 08:05 262661 /lib/x86_64-linux-gnu/ld-2.19.so
7f08cc82d000-7f08cc82e000 rw-p 00021000 08:05 262661 /lib/x86_64-linux-gnu/ld-2.19.so
7f08cc82e000-7f08cc82f000 rw-p 00000000 00:00 0
7fff702c3000-7fff702e4000 rw-p 00000000 00:00 0 [stack]
7fff7038d000-7fff7038f000 r-xp 00000000 00:00 0 [vdso]
7fff7038f000-7fff70391000 r--p 00000000 00:00 0 [vvar]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Abortado
我设定的文件限制:
labam@debian:~/distribidos/wildchildrenserver/bin/release$ulimit-n
四千零九十六
最佳答案
select参数的类型为“fd_set”,该集合通常限制为1024个连接。用“投票”代替。
请参阅此链接作为其他备选方案的参考:
Handling more than 1024 file descriptors, in C on Linux