ulimit

ulimit in Linux refers to a command used to manage user-level resource limits, helping control the system resources that individual users and processes can consume. It is part of the shell built-in commands and interacts with the Linux kernel’s resource management system.

There are different categories of resource limits that can be controlled by ulimit, including:

  1. File Descriptors (nofile): Limits the number of open file descriptors per process. It’s useful for controlling the number of files a process can open at once.
  2. CPU Time (cpu): Restricts the amount of CPU time (in seconds) that a process can use. When this limit is reached, the process will be killed.
  3. File Size (fsize): Controls the maximum size of files that a process can create.
  4. Memory Usage (as, rss): Limits the virtual memory (as) or the resident set size (rss) a process can use.
  5. Stack Size (stack): Sets the maximum stack size that a process can allocate.
  6. Core Dump Size (core): Defines the maximum size of core dumps generated by a process.

Types of Limits

ulimit allows setting two types of limits:

  • Soft Limit: This is a threshold that users can modify themselves within the range of the hard limit.
  • Hard Limit: This is the maximum limit that only the root user can modify. Once set, even the user cannot raise it beyond this point without root privileges.

Example of Usage

  • To check the current limits:

    ulimit -a

    This shows all resource limits for the current user session.

  • To set the number of open files (file descriptors):

    ulimit -n 4096
  • To set the maximum size of a core dump:

    ulimit -c unlimited

These limits are especially important for controlling resource usage in multi-user environments or on servers where resource exhaustion can affect system stability.