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
调整,需要修改内核参数或其他系统配置文件。通过以上步骤,你可以有效地调整系统资源分配策略,确保系统资源的合理使用。