Linux系統中操作檔案數過多導致的錯誤解決方案

來源:互聯網
上載者:User

   linux 開啟檔案數 too many open files 解決方案

  too many open files出現這句提示的原因是程式開啟的檔案/socket串連數量超過系統設定值。

  查看每個使用者最大允許開啟檔案數量

  代碼如下:

  ulimit -a

  fdipzone@ubuntu:~$ 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

  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

  其中 open files (-n) 1024 表示每個使用者最大允許開啟的檔案數量是1024

  查看當前系統開啟的檔案數量

  代碼如下:

  lsof | wc -l

  watch "lsof | wc -l"

  查看某一進程的開啟檔案數量

  代碼如下:

  lsof -p pid | wc -l

  lsof -p 1234 | wc -l

  設定open files數值方法

  代碼如下:

  ulimit -n 2048

  fdipzone@ubuntu:~$ ulimit -n 2048

  fdipzone@ubuntu:~$ 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) unlimited

  virtual memory (kbytes, -v) unlimited

  file locks (-x) unlimited

  這樣就可以把目前使用者的最大允許開啟檔案數量設定為2048了,但這種設定方法在重啟後會還原為預設值。

  永久設定方法

  代碼如下:

  vim /etc/security/limits.conf

  在最後加入

  代碼如下:

  * soft nofile 4096

  * hard nofile 4096

  最前的 * 表示所有使用者,可根據需要設定某一使用者,例如

  代碼如下:

  fdipzone soft nofile 8192

  fdipzone hard nofile 8192

  改完後登出一下就能生效。

  linux Argument list too long錯誤解決方案

  上一次需要刪除/tmp目錄下的所有檔案,檔案數量比較多。

  代碼如下:

  ls -lt /tmp | wc -l

  385412

  使用 rm * 後,系統提示錯誤 Argument list too long

  原因是在linux下,試圖傳太多參數給一個系統命令(ls *; cp *; rm *; cat *; etc..)時,就會出現 Argument list too long錯誤。

  解決方案如下:

  使用find -exec 遍曆,然後執行刪除便可。

  代碼如下:

  sudo find /tmp -type f -exec rm {} ;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.