關於RHEL6中ulimit的nproc限制

來源:互聯網
上載者:User

關於RHEL6中ulimit的nproc限制 ulimit 用於限制 shell 啟動進程所佔用的資源,支援以下各種類型的限制:所建立的核心檔案的大小、進程資料區塊的大小、Shell 進程建立檔案的大小、記憶體鎖住的大小、常駐記憶體集的大小、開啟檔案描述符的數量、分配堆棧的最大大小、CPU 時間、單個使用者的最大線程數、Shell 進程所能使用的最大虛擬記憶體。同時,它支援硬資源和軟資源的限制。  www.2cto.com  Linux檔案描述符可參見筆者之前的文章:http://www.bkjia.com/os/201212/177127.html
 關於RHEL6中ulimit的nproc限制,RHEL6和RHEL5還是有一些細節上的區別的:當前shell下更改使用者可開啟進程數 作為臨時限制,ulimit可以作用於通過使用其命令登入的 shell 會話,在會話終止時便結束限制,並不影響於其他 shell 會話。

 修改limits.conf設定檔生效[root@kumu ~]# ulimit -a         //查看當前設定檔ulimit全域係數core file size          (blocks, -c) 0data seg size           (kbytes, -d) unlimitedscheduling priority             (-e) 0file size               (blocks, -f) unlimitedpending signals                 (-i) 1829max locked memory       (kbytes, -l) 64max memory size         (kbytes, -m) unlimitedopen files                      (-n) 1024pipe size            (512 bytes, -p) 8POSIX message queues     (bytes, -q) 819200real-time priority              (-r) 0stack size              (kbytes, -s) 10240cpu time               (seconds, -t) unlimitedmax user processes              (-u) 1024virtual memory          (kbytes, -v) unlimitedfile locks                      (-x) unlimited[root@kumu ~]# vim /etc/security/limits.conf[root@kumu ~]# grep '^*' /etc/security/limits.conf*       soft    nproc       10240*       hard    nproc       10240*       soft    nofile      10240*       hard    nofile      10240[root@kumu ~]# 退出目前使用者,重新登入即可讓之前修改的limits生效[root@kumu ~]# ulimit -n10240[root@kumu ~]# ulimit -u         //發現nproc並沒有像nofile一樣而改變1024[root@kumu ~]# 經google搜尋獲知,RHEL6下引入了設定檔/etc/security/limits.d/90-nproc.conf(參見了@楊德華Devin 文章redhat5 和redhat6 root使用者不同的ulimits)[root@kumu ~]# cat /etc/security/limits.d/90-nproc.conf# Default limit for number of user's processes to prevent# accidental fork bombs.# See rhbz #432903 for reasoning. *          soft    nproc     1024[root@kumu ~]# 我們修改這個檔案嘗試是否因為該檔案影響,修改如下[root@kumu ~]# vim /etc/security/limits.d/90-nproc.conf[root@kumu ~]# cat /etc/security/limits.d/90-nproc.conf# Default limit for number of user's processes to prevent# accidental fork bombs.# See rhbz #432903 for reasoning. #*          soft    nproc     1024*          soft    nproc    65535[root@kumu ~]# 退出目前使用者,重新登入即可讓之前修改的limits生效,執行如下命令發現修改成功[root@kumu ~]# ulimit -u10240[root@kumu ~]# ulimit -n10240[root@kumu ~]# 由此可知,如果要修改設定檔limits.conf中的nproc限制上限是受檔案/etc/security/limits.d/90-nproc.conf中nproc值大小制約的,但是shell終端下是不受制約的 另外筆者猜想,如果使用*號讓全域使用者生效是受檔案/etc/security/limits.d/90-nproc.conf中nproc值大小制約的,而如果僅僅是針對某個使用者,那麼就不受該檔案nproc值大小的影響  www.2cto.com   [root@kumu ~]# vim /etc/security/limits.d/90-nproc.conf   //恢複系統預設設定[root@kumu ~]# cat /etc/security/limits.d/90-nproc.conf# Default limit for number of user's processes to prevent# accidental fork bombs.# See rhbz #432903 for reasoning. *          soft    nproc     1024#*          soft    nproc    65535[root@kumu ~]# vim /etc/security/limits.conf       //只針對某個使用者測試(這裡使用root)[root@kumu ~]# grep '^root' /etc/security/limits.confroot        soft    nproc       10240root        hard    nproc       10240[root@kumu ~]# 退出目前使用者,重新登入即可讓之前修改的limits生效,執行如下命令發現修改成功[root@kumu ~]# ulimit -u10240[root@kumu ~]# ulimit -n10240[root@kumu ~]# 筆者之前猜想正確,即只有當使用*號讓全域使用者生效的時候,生效的nproc的值大小是受檔案/etc/security/limits.d/90-nproc.conf中nproc值大小制約的,而如果僅僅是針對某個使用者,那麼就不受該檔案nproc值大小的影響。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.