Restrictions on the number of file descriptors in Linux Processes

Source: Internet
Author: User

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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.