tags : Linux

What is it?

  • A shell builtin that works on a per-process basis. Limit is then adopted by the shell that called it and inherited by children(i.e children will have their own limits, number will be same though).
  • The shell builtin essentially wraps getrlimit / setrlimit system calls.
  • Option in container tools like docker, podman. i.e it’ll set ulimit for the container sort of.
    • TODO: ulimit in containers is tricky, I’ve to check it properly when I get time. I mean it’s used slightly differently and nproc has some host specific things etc. Little complicated.

What about process?

  • Once a process starts, its ulimits are set. The process itself can change its soft ulimit up to the hard ulimit.
  • prlimit can help you change ulimits of running process

Relationship w limits.conf

Limits are a property of a process.

About limits.conf

  • The file does not affect system services.
  • /etc/security/limits.conf file provides configuration for the pam_limits PAM module
  • /etc/security/limits.conf allows setting resource limits for users and groups logged in via PAM.
  • However /etc/security/limits.conf does not work for the system using systemd. Following needs to be changed instead.
    • /etc/systemd/system.conf
    • /etc/systemd/user.conf
    • /etc/systemd/system/unit.d/override.conf

Types of limits

  • Hard limits
    • Set by root and enforced by the kernel.
    • Mark the maximum value which cannot be exceeded by setting a soft limit.
  • Soft limits
    • Configured by the user within the range allowed by the hard limits.
    • Simply the currently enforced limits.

System and User limits

Limits are inherited when a child process is created

  • System wide limits
    • Should be set during the system initialization in init scripts, systemd specific conf files etc.
  • User limits
    • Should be set during user login for example by using pam_limits (/etc/security/limits.conf)