Linux handle restrictions

Source: Internet
Author: User

Linux handle restrictions

Linux --- Process Handle restriction Summary

!! This article is only tested on RHEL6.4.

Linux handles can be divided into 1 system level limit and 2 user level limit:

/Proc/sys/fs/nr_open>/proc/sys/fs/file-max> = ulimit-Hn> = ulimit-Sn

1 system-level limit: 1.1/proc/sys/fs/nr_open

The maximum number of file handles supported by the System File System. The default value is 1048576 (1 M). The maximum value is limited by the system memory. This is the maximum value for all restrictions.

1.2/proc/sys/fs/file-max

The maximum number of file handles supported by the system file system must be smaller than nr_open. view the command (the following three commands are equivalent ):

[Root @ vm-cdh4 ~] # Sysctl-a | grep-I file-max -- color
Fs. file-max = 188436
[Root @ vm-cdh4 ~] # Cat/proc/sys/fs/file-max
188436
[Root @ vm-cdh4 ~] # Sysctl-e fs. file-max
Fs. file-max = 188436

Run the following command to view the number of opened file descriptors used by the current system:

[Root @ vm-cdh4 ~] # Cat/proc/sys/fs/file-nr
832 0 188436

File-max = 188436

1.3 change file-max

Temporary changes and disappears after restart:

[Root @ vm-cdh4 ~] # Sysctl-w fs. file-max = 102400

Add permanent changes to/etc/sysctl. conf (applicable to 2.2 and 2.4 kernels ):

Fs. file-max = 102400
#### For Kernel 2.2 only:
#### Fs. inode-max = 102400

After/etc/sysctl. conf is changed, run the following command to make the change take effect immediately:

[Root @ vm-cdh4 ~] # Sysctl-p

2. user-level limit: 2.1 hard upper limit: ulimit-Hn

The maximum number of handles of a single process. <= file-max. view the command:

[Root @ vm-cdh4 ~] # Ulimit-Hn
4096

Temporary changes and disappears after restart:

[Root @ vm-cdh4 ~] # Ulimit-hn8192
[Root @ vm-cdh4 ~] # Ulimit-Hn
8192

2.2 Soft Upper Limit ulimit-Sn

The maximum number of handles for a single process. <= ulimit-Hn. view the command:

[Root @ vm-cdh4 ~] # Ulimit-Sn
1024
[Root @ vm-cdh4 ~] # Ulimit-n
1024

Temporary changes and disappears after restart:

[Root @ vm-cdh4 ~] # Ulimit-Sn 8000
[Root @ vm-cdh4 ~] # Ulimit-n
8000

2.3 modify the maximum number of handles of a single process

At the same time, the soft and hard limits (<= file-max) are temporarily modified and disappear after restart:

[Root @ vm-cdh4 ~] # Ulimit-shn10240

Permanently modify the hard and soft limits (RHEL6.4) in/etc/security/limits. conf (* indicates all users ):

#......
# @ Student-maxlogins 4

* Hard nofile 10240
* Soft nofile 10240

# End of file

This article permanently updates the link address:

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.