File descriptor FD is a relatively limited resource in Linux. The number of FD files in a single process is limited. The default value is 1024.
View the FD quantity limit of the current session
# Ulimit-n
Modify the FD quantity limit for the current session. Note that it is only valid for the current session.
# Ulimit-N your_need
The system function can be used to modify the FD limitation in the program, which is only valid for the current process.
# Include <sys/resource. h> struct rlimit {rlim_t rlim_cur; // soft limit rlim_t rlim_max; // hard limit}; // get resource limitint getrlimit (INT resource, struct rlimit * rlim ); // set resource limitint setrlimit (INT resource, const struct rlimit * rlim );
API details can refer to the http://www.kernel.org/doc/man-pages/online/pages/man2/setrlimit.2.html
In the rlimit structure, rlim_cur corresponds to soft limit, and rlim_max corresponds to hard limit. Note the following:
Soft limit is the upper limit of resources allowed by the kernel. For example, FD; hard limit is the upper limit of soft limit; rlim_max> = rlim_cur; users with root permissions can modify hard limit.