I know that Linux limits the maximum amount of open descriptors, usually to 1024.
Now say I need to create a server which will handle more than 1024 users, 2000 for example, without tampering with the kernel.
This means I couldn't handle all of them by just keeping a descriptor open for each client and polling them select() since my kernel only supports 1024 hosts.
But let's say I want to create a concurrent server and spawn a child/thread for each connected client
1. Does a child share the parent's descriptor limit, in other words could I spawn 2000 children and handle each client separately?
2. Does a thread share parent's descriptor limit, could I create 2000 threads, each handling one connection?
- 1
1 Answers
On Linux, there is a system wide limit of the number of fds open: fs.file-max. Also, a separate per process limit called nofile via the pam_limits module (ulimit).
https://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/
How do ulimit -n and /proc/sys/fs/file-max differ?
Does a child share the parent's descriptor limit
The system total fs.file-max limit yes, the per process ulimit no.
Now say I need to create a server which will handle more than 1024 users, 2000 for example, without tampering with the kernel.
In a file in /etc/security/limits.d/
set nofile for the user running the server at least as many as needed, perhaps 4000.
In a file in /etc/sysctl.d/
set fs.file-max to at least the total number of connections, plus some for other programs. Perhaps 200000.
- 30,009
- 1
- 17
- 32