對不起,這個問題有幾個層次,但都處理打開文件的數量。Linux和系統上的Linux用戶打開文件的數量是多少?
我在我的應用程序日誌中收到了「太多打開的文件」消息,我們正在開發該應用程序。有人建議我:
- 找到當前正在使用的打開文件,全系統的數量和每用戶
- 查找內容的系統和用戶打開文件的限制是。
我跑ulimit -n
它返回1024.我也看了/etc/limits.conf文件中沒有什麼特別的東西。 /etc/sysctl.conf也沒有修改。我將列出以下文件的內容。我也跑lsof | wc -l
,返回5000+行(如果我正確使用它)。
所以,我的主要問題是:
- 如何找到的每個用戶可以打開的文件數?軟限制是否在/etc/limits.conf中找到/定義了nofile設置?因爲我沒有碰到/etc/limits.conf,所以默認是什麼?
- 如何查找允許系統範圍內打開文件的數量?是limits.conf中的硬限制嗎?如果limits.conf未被修改,那麼默認數字是多少?
- ulimit爲打開的文件返回的數字是多少?它說的是1024,但是當我運行lsof並計算行數時,它超過了5000+,所以有些東西沒有點擊我。有沒有其他我應該運行的cmds或文件來查看以獲得這些限制?在此先感謝您的幫助。 limits.conf中的
內容
# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain> <type> <item> <value>
#
#Where:
#<domain> can be:
# - an user name
# - a group name, with @group syntax
# - the wildcard *, for default entry
# - the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
#
#<item> can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open files
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit (KB)
# - maxlogins - max number of logins for this user
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-20, 19]
# - rtprio - max realtime priority
#
#<domain> <type> <item> <value>
#
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4
# End of file
內容sysctl.conf的
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536
# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736
# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
# the interval between the last data packet sent and the first keepalive probe
net.ipv4.tcp_keepalive_time = 600
# the interval between subsequential keepalive probes
net.ipv4.tcp_keepalive_intvl = 60
# the interval between the last data packet sent and the first keepalive probe
net.ipv4.tcp_keepalive_time = 600
# the interval between subsequential keepalive probes
net.ipv4.tcp_keepalive_intvl = 60
# the number of unacknowledged probes to send before considering the connection dead and notifying the application layer
net.ipv4.tcp_keepalive_probes = 10
# the number of unacknowledged probes to send before considering the connection dead and notifying the application layer
net.ipv4.tcp_keepalive_probes = 10
# try as hard as possible not to swap, as safely as possible
vm.swappiness = 1
fs.aio-max-nr = 1048576
#fs.file-max = 4096
想一想一個問題:爲什麼你用完了打開的文件?您是否真的需要一次打開1024個文件,或者您是否確保文件在完成時關閉。當然有合理的理由需要打開大量文件,但不要爲了在文件耗盡之後用完文件而增加限制,因爲你正在泄漏資源。 –
@JonathanLeffler,thx的評論。我同意,我想弄清楚誰是罪魁禍首,並阻止它。我會研究lsof,看看我能否找到那個過程。 – Classified