在一般系统上, 进程打开的句柄数目是1024, 但在有的系统上, 却不是这个数, 举个栗子:
yyyyyy$ ulimit -n
100001 下面,我们来看看程序:
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <fcntl.h>
#include <fcntl.h>
void fun(unsigned int n)
{
struct timeval tv; // 超时时间
tv.tv_sec = 3;
tv.tv_usec = 500; // 注意单位是微秒
fd_set rdfds;
FD_ZERO(&rdfds); // 描述集初始化
int iSock = 0;
for(unsigned int i = 0; i < n; i++)
{
iSock = socket(AF_INET

博客讨论了在某些系统中,进程句柄限制并非默认的1024,当使用select导致句柄数量超出限制时,可能会引发core dump。作者建议服务器端避免使用select,并在客户端尽可能减少使用。
1385

被折叠的 条评论
为什么被折叠?



