


How to limit user resources in Linux? How to configure ulimit?
May 29, 2025 pm 11:09 PMLinux system restricts user resources through the ulimit command to prevent excessive use of resources. 1. Ulimit is a built-in shell command that can limit the number of file descriptors (-n), memory size (-v), thread count (-u), etc., which are divided into soft limit (current effective value) and hard limit (maximum upper limit). 2. Temporary modifications use the ulimit command directly, such as ulimit -n 2048, but it is only valid for the current session. 3. For permanent effect, modify /etc/security/limits.conf and PAM configuration files, and add session required pam_limits.so. 4. The systemd service needs to set parameters such as LimitNOFILE, LimitNPROC in the unit file, and overload systemd takes effect.
The Linux system restricts user resources, mainly through the mechanism provided by the kernel to control the process's use of system resources. Among them, ulimit
is a commonly used command line tool to set or view resource restrictions under the current shell session. It is suitable for preventing a user or program from occupying too much resources, such as memory, CPU time, number of opened files, etc.
Here are some common configuration methods and precautions:
1. What is ulimit? What resources can be limited?
ulimit
is a built-in command in Linux shell to control the usage limit of system resources. What it may limit includes but is not limited to:
- Maximum number of open file descriptors (
-n
) - The maximum memory size that a single process can use (
-v
) - Maximum number of threads (
-u
) - CPU time (
-t
) - Stack space size (
-s
)
These limitations are divided into soft limit and hard limit :
- The soft limit is the value that you are currently in effect. Ordinary users can only adjust to a value that does not exceed the hard limit.
- The hard limit is set by root and cannot be exceeded by ordinary users.
For example, to view the resource limits of the current user, you can use:
ulimit -a
2. How to temporarily modify ulimit settings?
If you just want to temporarily modify certain restrictions in the current terminal session, you can use the ulimit
command directly. For example:
ulimit -n 2048 # Set the number of open files to 2048 ulimit -u 1024 # Set up to 1024 processes per user
Note that this modification is only valid in the current shell session, and will be invalid after restarting or opening a new terminal.
In addition, some restrictions can only be raised to the range of hard restrictions. If you need to break through hard restrictions, you have to use root permissions to modify them.
3. How to take effect permanently? How to change the configuration file?
To make the ulimit setting take effect every time you log in, you need to modify the system configuration file.
There are mainly two documents:
-
/etc/security/limits.conf
-
/etc/pam.d/common-session
(Debian system) or/etc/pam.d/login
(RedHat system)
Add something like this in limits.conf
:
* soft nofile 4096 * hard nofile 8192 www-data soft nproc 2048 www-data hard nproc 4096
This means that the soft limit for all users ( *
) is 4096 file descriptors, and the hard limit is 8192; and the process limit for www-data
users is also set.
In addition, make sure that the PAM module is loaded with pam_limits.so
and add it to /etc/pam.d/common-session
:
session required pam_limits.so
In this way, the system will apply the ulimit rules you set every time the user logs in.
4. How to set resource restrictions for systemd service?
If you are using a service managed through systemd, such as nginx, redis, and custom scripts, you cannot rely on limits.conf
, because the systemd service does not follow the PAM process.
At this time, resource restrictions should be set in the service unit file. For example, add in /etc/systemd/system/myapp.service
:
[Service] LimitNOFILE=8192 LimitNPROC=4096
Then reload systemd and restart the service:
systemctl daemon-reexec systemctl restart myapp
This will allow you to control the resource limit of a certain service individually.
Basically that's it. Ulimit looks simple, but pay attention to the way it takes effect and scope of action. Sometimes you set it but it doesn't take effect, it may be because the service does not go through the PAM process or is overwritten by systemd. When encountering problems, remember to check the logs, or use the prlimit
command to view the actual limitations of the specific process.
The above is the detailed content of How to limit user resources in Linux? How to configure ulimit?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In the digital currency market, real-time mastering of Bitcoin prices and transaction in-depth information is a must-have skill for every investor. Viewing accurate K-line charts and depth charts can help judge the power of buying and selling, capture market changes, and improve the scientific nature of investment decisions.

The failure to register a Binance account is mainly caused by regional IP blockade, network abnormalities, KYC authentication failure, account duplication, device compatibility issues and system maintenance. 1. Use unrestricted regional nodes to ensure network stability; 2. Submit clear and complete certificate information and match nationality; 3. Register with unbound email address; 4. Clean the browser cache or replace the device; 5. Avoid maintenance periods and pay attention to the official announcement; 6. After registration, you can immediately enable 2FA, address whitelist and anti-phishing code, which can complete registration within 10 minutes and improve security by more than 90%, and finally build a compliance and security closed loop.

This article lists the top ten trading software in the currency circle, namely: 1. Binance, a world-leading exchange, supports multiple trading modes and financial services, with a friendly interface and high security; 2. OKX, rich products, good user experience, supports multilingual and multiple security protection; 3. gate.io, known for strict review and diversified trading services, attaches importance to community and customer service; 4. Huobi, an old platform, has stable operations, strong liquidity, and has a great brand influence; 5. KuCoin, has large spot trading volume, rich currency, low fees, and diverse functions; 6. Kraken, a US compliance exchange, has strong security, supports leverage and OTC trading; 7. Bitfinex, has a long history, professional tools, suitable for high

Identifying the trend of the main capital can significantly improve the quality of investment decisions. Its core value lies in trend prediction, support/pressure position verification and sector rotation precursor; 1. Track the net inflow direction, trading ratio imbalance and market price order cluster through large-scale transaction data; 2. Use the on-chain giant whale address to analyze position changes, exchange inflows and position costs; 3. Capture derivative market signals such as futures open contracts, long-short position ratios and liquidated risk zones; in actual combat, trends are confirmed according to the four-step method: technical resonance, exchange flow, derivative indicators and market sentiment extreme value; the main force often adopts a three-step harvesting strategy: sweeping and manufacturing FOMO, KOL collaboratively shouting orders, and short-selling backhand shorting; novices should take risk aversion actions: when the main force's net outflow exceeds $15 million, reduce positions by 50%, and large-scale selling orders

First, select well-known platforms such as Binance Binance or Ouyi OKX, and prepare your email and mobile phone number; 1. Visit the official website of the platform and click to register, enter your email or mobile phone number and set a high-strength password; 2. Submit information after agreeing to the terms of service, and complete account activation through the email or mobile phone verification code; 3. After logging in, complete identity authentication (KYC), enable secondary verification (2FA), and regularly check security settings to ensure account security. After completing the above steps, you can successfully create a BTC digital currency account.

cronisusedforpreciseschedulingonalways-onsystems,whileanacronensuresperiodictasksrunonsystemsthataren'tcontinuouslypowered,suchaslaptops;1.Usecronforexacttiming(e.g.,3AMdaily)viacrontab-ewithsyntaxMINHOURDOMMONDOWCOMMAND;2.Useanacronfordaily,weekly,o

1. Download and install the application through the official recommended channel to ensure safety; 2. Access the designated download address to complete the file acquisition; 3. Ignore the device safety reminder and complete the installation as prompts; 4. You can refer to the data of mainstream platforms such as Huobi HTX and Ouyi OK for market comparison; the APP provides real-time market tracking, professional charting tools, price warning and market information aggregation functions; when analyzing trends, long-term trend judgment, technical indicator application, trading volume changes and fundamental information; when choosing software, you should pay attention to data authority, interface friendliness and comprehensive functions to improve analysis efficiency and decision-making accuracy.

Binance provides bank transfers, credit cards, P2P and other methods to purchase USDT, USDC and other stablecoins, with fiat currency entrance and high security; 2. Ouyi OKX supports credit cards, bank cards and third-party payment to purchase stablecoins, and provides OTC and P2P transaction services; 3. Sesame Open Gate.io can purchase stablecoins through fiat currency channels and P2P transactions, supporting multiple fiat currency recharges and convenient operation; 4. Huobi provides fiat currency trading area and P2P market to purchase stablecoins, with strict risk control and high-quality customer service; 5. KuCoin supports credit cards and bank transfers to purchase stablecoins, with diverse P2P transactions and friendly interfaces; 6. Kraken supports ACH, SEPA and other bank transfer methods to purchase stablecoins, with high security
