
Table of Contents 🔈Introduction Redhat recently introduced the System Storage Manager (SSM), a unified user interface that allows uses to manage complicated systems in a
Learn how to manage system resource limits using ulimit and /etc/security/limits.conf on Linux. Discover key concepts, practical examples, and best practices for controlling file descriptors, processes, memory, and more.
When managing Linux systems, one of the essential aspects of system administration is ensuring that processes do not consume excessive resources. By setting appropriate resource limits, you can prevent a single process from consuming all available CPU, memory, or file descriptors, which can negatively impact the overall system performance. Two primary tools for controlling these resource limits are ulimit and /etc/security/limits.conf. Understanding how to configure and manage these limits is vital for maintaining a stable, secure, and efficient system.
In this blog post, we’ll explore how to manage system resource limits using ulimit and the /etc/security/limits.conf file. We will cover the various types of limits, practical examples, and best practices for configuring these limits effectively.
ulimit is a command-line utility in Unix-like operating systems that allows users to view or set resource limits for processes running in their user session. These resource limits govern the maximum amount of system resources that a user or process can consume. They apply only to processes running in the current shell session.
To see the current limits, you can run the ulimit command without any arguments:
ulimit -a
This will display the current limits for various resources like the number of file descriptors, process limits, memory, and more. Example output:
core file size (blocks, -c) 0
data area size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192
▶️ Common |
|
|
|
|
|
There are various types of resource limits you can control. Some of the most commonly adjusted limits include:
| Resource Type | Description |
|---|---|
| File Descriptors | Controls the number of files a process can open simultaneously. |
| Processes | Limits the number of processes a user can create. |
| Memory | Limits the amount of memory a process can use. |
| Stack Size | The maximum size of the stack for a process. |
| CPU Time | The maximum amount of CPU time a process can consume. |
| Core Dumps | Defines the size of the core dump files created when a process crashes. |
These limits are crucial for system stability. Without proper limits, one misbehaving process could exhaust all system resources, leading to system crashes or slowdowns.
The /etc/security/limits.conf file is a system-wide configuration file used to set resource limits for users or groups on Linux systems. Unlike ulimit, which only applies to the current session, the limits defined in this file are persistent across reboots and can be configured for individual users or groups.
The /etc/security/limits.conf file uses a specific syntax to define the limits:
-
Where:
|
|
|
|
|
|
ulimit can be used to set resource limits on a per-session basis. However, these limits are temporary and will not persist after you close the session. To adjust a limit, use the following command syntax:
ulimit -
For example, to set the maximum number of open files to 2048, you would use:
ulimit -n 2048
To set the maximum number of processes for the user, you can run:
ulimit -u 500
To make persistent changes to system resource limits, you need to edit the /etc/security/limits.conf file. Here’s an example of how to configure resource limits for a user:
🔄 Open the file for editing: |
sudo vim /etc/security/limits.conf
🔄 Add your resource limits |
For instance, to limit the number of open files (nofile) and processes (nproc) for a specific user (user1):
user1 soft nofile 1024
user1 hard nofile 2048
user1 soft nproc 100
user1 hard nproc 150
This ensures that:
|
|
|
Here are some practical examples of configuring system resource limits:
🔄 Example 1: Limit Open Files for All Users |
To limit the number of open files for all users to 2048 (soft) and 4096 (hard), you would add the following lines to /etc/security/limits.conf:
* soft nofile 2048
* hard nofile 4096
🔄 Example 2: Limit Processes for a Group |
To limit the number of processes for a specific group (developers) to 200 (soft) and 300 (hard), you would add:
@developers soft nproc 200
@developers hard nproc 300
🔄 Example 3: Limit CPU Time for a Specific User |
To restrict the amount of CPU time for a user (user2) to 60 minutes (3600 seconds), add the following:
user2 soft cpu 3600
user2 hard cpu 7200
|
|
|
|
|
Managing resource limits is a critical part of maintaining a healthy Linux system. By using ulimit for session-specific limits and /etc/security/limits.conf for persistent user and group limits, you can ensure that system resources are allocated efficiently. Proper configuration helps prevent system overloads and ensures that no single process can monopolize resources, which can lead to system instability.
By following best practices and regularly reviewing resource limits based on system usage, you can maintain optimal system performance and security.
Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.

Table of Contents 🔈Introduction Redhat recently introduced the System Storage Manager (SSM), a unified user interface that allows uses to manage complicated systems in a

Discover 25 essential Linux commands for efficient storage management. Learn how to monitor disk usage, manage partitions, create filesystems, and optimize storage performance with detailed

Learn how to securely deploy GFS2 on encrypted volumes over multipath storage in a high-availability Linux cluster. Includes CLI examples, automation tips, and best practices.
