问题
What is the difference between these 2 linux errors in
errno.h
? 23 and 24I tried 2 different sites but can't understand difference between the two.
[EMFILE] Too many open files. [ENFILE] Too many files open in system.
# define ENFILE 23 /* File table overflow */ # define EMFILE 24 /* Too many open files */
Also, I am getting errno 24 and socket call failing at 974th time. (
AF_INET
UDP datagram socket)When I did a
cat /proc/sys/fs/file-max
I am seeing a value of 334076 ulimit -n showing 1024Any idea what can be done to increase limit?
回答1:
For 1) Both error codes are about the situation with too many opened files. EMFILE is too many files opened in your process. ENFILE is too many files opened in the entire system.
回答2:
You can increase the maximum number of open files / file descriptors
sysctl -w fs.file-max=100000
Or open
/etc/sysctl.conf
and append/change fs.file-max to the number you need:
fs.file-max = 100000
Then run
sysctl -p
to reload the new settings
If you don't want to set system-wide FD (file-descriptor) limits, you can set the user-level FD limits.
You need to edit
/etc/security/limits.conf file
And for user YOUR_USER, add these lines:
YOUR_USER soft nofile 4096
YOUR_USER hard nofile 10240
to set the soft and hard limits for user YOUR_USER.
Save and close the file.
To see the hard and soft limits for user YOUR_USER:
su - YOUR_USER
ulimit -Hn
ulimit -Sn
来源:https://stackoverflow.com/questions/24862733/difference-between-linux-errno-23-and-linux-errno-24