31.提示錯誤fopen_means Too many open files
一:列印提示fopen 出錯:
open_file_and_get_length:175 fopen /var/1608536431170.jpg errno = 24, means: Too many open files
二:原因:
1.Too many open files從字面意思來看,就是程式開啟的檔案數過多,
不過這裡的files不單是檔案的意思,也包括開啟的通訊連線(如socket),正在監聽的埠等等;
這個錯誤通常是開啟的檔案超過了系統限制。
因為linux系統提供的檔案描述符最多隻有1024個,如下:
root@user126:# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 20
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024 //最大開啟個數1024(包含socket的檔案描述符)
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
三:解決:
1.如系統確實需要更多的檔案描述符,可使用命令修改:ulimit -n 2048
但是這種方式修改重啟後還是會恢復預設值。
root@user126:# ulimit -n 2048
root@user126:# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 20
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 2048 //修改成功:
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 2048
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
root@user126:/mnt/yanghang/testdir/SourceInsight7/MainCode_371/MainCode/build#
2.將允許開啟數寫入到配置檔案;
vim /etc/security/limits.conf
#在最後加入, *號表示所有使用者:
* soft nofile 2048
* hard nofile 2048
3.檢視某一程式佔用檔案描述符的個數:
aston@ubuntu:~$ ps
PID TTY TIME CMD
2580 pts/7 00:00:00 bash
2652 pts/7 00:00:00 ps
aston@ubuntu:~$ lsof -p 2580 | wc -l
18
4.寫入日誌,分析這被開啟的18個檔案描述符:
aston@ubuntu:~$ lsof -p 2580 > /mnt/hgfs/share/test/6/openfiles.log
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 2580 aston cwd DIR 8,1 4096 675479 /home/aston
bash 2580 aston rtd DIR 8,1 4096 2 /
bash 2580 aston txt REG 8,1 986672 131079 /bin/bash
bash 2580 aston mem REG 8,1 46812 918593 /lib/i386-linux-gnu/libnss_files-2.19.so
bash 2580 aston mem REG 8,1 92036 918587 /lib/i386-linux-gnu/libnsl-2.19.so
bash 2580 aston mem REG 8,1 11688000 403327 /usr/lib/locale/locale-archive
bash 2580 aston mem REG 8,1 1758972 918518 /lib/i386-linux-gnu/libc-2.19.so
bash 2580 aston mem REG 8,1 13856 918535 /lib/i386-linux-gnu/libdl-2.19.so
bash 2580 aston mem REG 8,1 133164 918664 /lib/i386-linux-gnu/libtinfo.so.5.9
bash 2580 aston mem REG 8,1 26256 400379 /usr/lib/i386-linux-gnu/gconv/gconv-modules.cache
bash 2580 aston mem REG 8,1 42668 918603 /lib/i386-linux-gnu/libnss_nis-2.19.so
bash 2580 aston mem REG 8,1 30560 918589 /lib/i386-linux-gnu/libnss_compat-2.19.so
bash 2580 aston mem REG 8,1 134380 918494 /lib/i386-linux-gnu/ld-2.19.so
bash 2580 aston 0u CHR 136,7 0t0 10 /dev/pts/7
bash 2580 aston 1u CHR 136,7 0t0 10 /dev/pts/7
bash 2580 aston 2u CHR 136,7 0t0 10 /dev/pts/7
bash 2580 aston 255u CHR 136,7 0t0 10 /dev/pts/7
四:是否是程式問題:
1.如果對程式有足夠的瞭解的話,那麼對程式開啟的檔案描述符上限一定有一定的預估,
如果感覺該數字異常,就需要進一步檢視:
lsof -p 程式id > openfiles.log
獲得當前佔用檔案描述符的全部詳情進行分析;
*開啟的這些檔案是不是都是必要的;
*定位到開啟這些檔案的程式碼;
*是否程式操作了檔案寫入,但是沒有進行正常的關閉;
*是否程式進行了socket等通訊,但是沒有正常關閉(也就是沒有超時結束的機制);
如果存在這些問題,無論系統的檔案描述符設定多大,隨著時間的推移,也一定會用完。
相關文章
- Too many open files報錯處理
- mysql備份提示 too many open files Errornumber 24MySqlError
- docker中使用systemctl命令時報Too many open files錯誤Docker
- nginx 報錯 accept4 () failed (24: Too many open files)NginxAI
- Ubuntu 解決 Too many open files 問題Ubuntu
- 解決 Too many symbol filesSymbol
- Too many files with unapproved license異常APP
- 從原始碼角度談談open_files_limit的生成邏輯及"Too many open files"的解決思路原始碼MIT
- MySQL問題處理——1040錯誤Too many connectionsMySql
- linux Too Many Files 問題檢視和解決方法Linux
- React報錯之Too many re-rendersReact
- too many open files 與程式網路連線資料檢視[轉載自北風之神巨佬的文章]
- 解決 ln -s 軟連結產生的Too many levels of symbolic links錯誤Symbol
- windows ssh遠端登入阿里雲遇到permissions are too open的錯誤Windows阿里
- MySQL ERROR 1040: Too many connectionsMySqlError
- mysql報錯Changed limits: max_open_files: 5000MySqlMIT
- IntelliJ IDEA 執行專案的時候提示 Command line is too long 錯誤IntelliJIdea
- 如何修復 SPF PermError: too many DNS lookupsErrorDNS
- 執行alter database open resetlogs提示ORA-00392和ORA-00312錯誤Database
- nginx 修改 max open files limitsNginxMIT
- [20230104]Oracle too many parse errors PARSE ERROR.txtOracleError
- MySQL錯誤提示(10061)MySql
- [20200309]rlwrap: error: Cannot execute sqlplus: Too many levels of symbolic linErrorSQLSymbol
- ValueError: output parameter for reduction operation logical_and has too many dimensions ?Error
- Nessus提示API Disabled錯誤API
- onethink安裝提示錯誤
- 解決:ChatGPT too many requests in 1 hour.Try again laterChatGPTAI
- PbootCMS錯誤提示:執行SQL發生錯誤!錯誤:no such column: def1bootSQL
- 網站提示400錯誤:錯誤請求怎麼辦網站
- hadoop 啟動 Permissions for id_rsa are too openHadoop
- 安裝golang tour,提示錯誤Golang
- 如何關閉PHP錯誤提示PHP
- Method has too many Body parameters: public abstract com.cloud.module.smartkeCloud
- 刪除大量檔案Argument list too long錯誤解決
- 如何處理錯誤訊息Please install the Linux kernel header filesLinuxHeader
- myeclipse中提示Hot Code Replace Failed提示窗錯誤EclipseAI
- pbootcms模板報錯提示PHP Warning: Unknown: open_basedir restrictionbootPHPREST
- TCP網路除錯助手提示錯誤:“1035:未知錯誤” 解決方案TCP除錯