【问题标题】:How to set resource limits for init on boot?如何在启动时为 init 设置资源限制?
【发布时间】:2015-10-11 07:37:59
【问题描述】:

我正在尝试找到一种方法来在启动期间为 init 进程设置 rlimit 值。通常,rlimit 是通过调用“setrlimit”系统调用来设置的。

所以我想知道有没有办法在启动时调用系统调用(比如在 shell 脚本中调用它)?或者,有没有其他方法可以执行setrlimit的等效操作?

【问题讨论】:

  • 您确定要设置init 本身而不是它启动的服务吗?
  • 我知道这听起来不合适,但是是的,我认为在这种特定情况下还可以。如果我找不到办法,我会改为设置服务。

标签: linux shell operating-system system-calls


【解决方案1】:

在 Linux 上,您可以使用 prlimit syscall/utility 为其他进程设置资源限制:

prlimit — get and set process resource limits
prlimit [options] [ −−resource [=limits] ] [ −−pid PID ]

int prlimit(pid_t pid, int resource, const struct rlimit *new_limit,
            struct rlimit *old_limit);

您可以根据需要在启动时运行它,例如在 /etc/rc.local 或等效项中运行,或者在 crontab 中运行 @reboot(如果支持)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 2010-11-06
    • 2012-12-23
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多