理解Linux中文件句柄数量限制file description

    技术2022-07-10  95

    问题描述

    程序中需要打开很多文件句柄,Linux有没有数量限制呢?

    In Linux, you can change the maximum amount of open files.

    Find Linux Open File Limit

    The value is stored in :

    $ cat /proc/sys/fs/file-max

    Check Hard/Soft Limit in Linux

    $ ulimit -Hn $ ulimit -Sn

    Check System wide File Descriptors Limits in Linux

    Global limits

    sysctl is used to configure kernel parameters at runtime

    # To increase open file limit to 500000, the change remain active until the next reboot $ sysctl -w fs.file-max=500000 # apply them permanently $ vi /etc/sysctl.conf # add the following line fs.file-max=500000 # Users will need to logout and login again for the changes to take effect, if you want to apply the limit immediately, you can use: $ sysctl -p

    User limits

    $ vi /etc/security/limits.conf # <domain> <type> <item> <value> # example marin hard nofile 4096 marin soft nofile 1024

    References

    How to Increase Number of Open Files Limit in Linux
    Processed: 0.010, SQL: 9