ulimit
是一個用于控制 shell 進程及其子進程可以使用的系統資源的命令。通過 ulimit
,你可以限制用戶或進程的資源使用,例如文件描述符數量、進程數等。以下是如何使用 ulimit
調整系統資源分配策略的一些基本步驟:
查看當前限制:
ulimit -a
這將顯示所有當前的限制。
設置特定資源的限制:
ulimit -n <number>
ulimit -u <number>
ulimit -t <seconds>
ulimit -v <kilobytes>
ulimit -m <number>
要永久調整 ulimit
設置,你需要編輯系統的配置文件。
編輯用戶的 shell 配置文件(例如 .bashrc
或 .bash_profile
):
nano ~/.bashrc
或者
nano ~/.bash_profile
添加 ulimit
設置:
ulimit -n <number>
ulimit -u <number>
保存并退出編輯器,然后重新加載配置文件:
source ~/.bashrc
或者
source ~/.bash_profile
編輯 /etc/security/limits.conf
文件:
sudo nano /etc/security/limits.conf
添加以下行(替換 <username>
和 <number>
):
<username> soft nofile <number>
<username> hard nofile <number>
<username> soft nproc <number>
<username> hard nproc <number>
保存并退出編輯器。
/etc/security/limits.conf
需要 root 權限。ulimit
調整,需要修改內核參數或其他系統配置文件。通過以上步驟,你可以有效地調整系統資源分配策略,確保系統資源的合理使用。