Typically socket “open” call doesn’t fail unless you have missed out closing the previous connections using “close” system call. Typically Linux/Unix sets a maximum limit for the number of open FDs. That means you can’t keep FDs in open state more than certain number. These settings can’t be changed as a normal user of the system.

These limits can be seen using “ulimit -a” command.

[neo@techpulp ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31729
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
[neo@techpulp ~]#

From the above limits, it is evident that maximum opened files is limited to 1024. That means your process or server can’t keep more than 1024 connections open.

You can change the limit using “ulimit -n” command. You will have to run this with super user permissions and run the program/server in that environment. Please note that the change of these limits take effect only for the processes created from the same shell. It is not system-wide change.

The following command sets the limit to 10240.

[neo@techpulp ~]# ulimit -n 10240