


How to limit user resources in Linux? How to configure ulimit?
Linux 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

The most suitable tools for querying stablecoin markets in 2025 are: 1. Binance, with authoritative data and rich trading pairs, and integrated TradingView charts suitable for technical analysis; 2. Ouyi, with clear interface and strong functional integration, and supports one-stop operation of Web3 accounts and DeFi; 3. CoinMarketCap, with many currencies, and the stablecoin sector can view market value rankings and deans; 4. CoinGecko, with comprehensive data dimensions, provides trust scores and community activity indicators, and has a neutral position; 5. Huobi (HTX), with stable market conditions and friendly operations, suitable for mainstream asset inquiries; 6. Gate.io, with the fastest collection of new coins and niche currencies, and is the first choice for projects to explore potential; 7. Tra

Binance App provides millisecond updated real-time trading prices of stablecoins such as USDT and USDC, which is the benchmark reference for the world's largest trading market; 2. Ouyi App not only displays precise market conditions, but also supports the linkage of technical analysis and financial products, suitable for in-depth traders; 3. Huobi (HTX) App has a wide influence in the Asian market, and its C2C quotation provides an important basis for off-market prices; 4. Gate.io App has rich coins listed, suitable for users who pay attention to mainstream and emerging stablecoins; 5. CoinMarketCap aggregates the weighted average prices of global exchanges, providing comprehensive data and historical charts, suitable for macro analysis; 6. CoinGecko evaluates exchanges and assets with trust scores, with a wider data dimension, and is a market.

Binance App data is the most authoritative and millisecond real-time, suitable for users who need one-stop transactions and price query; 2. The Ouyi App interface is refreshing and supports Web3 account integration, and the simplified version is more friendly to users who only need to query prices; 3. As a third-party aggregation platform, CoinGecko can compare prices across exchanges and use lightweight, suitable for research and analysis, but weak real-time; 4. Huobi App has stable functions and wide user base, but insufficient innovation and market share has declined; 5. Gate.io provides rich stable currency types and emerging project data, which is powerful but has a crowded interface, making it difficult for novices to get started.

Open Yandex browser; 2. Search and enter the official Binance website with a lock icon starting with https; 3. Check the address bar domain name to confirm as the official Binance address; 4. Click to log in or register to use the service on the official website; 5. It is recommended to download the App through the official app store, Android users use Google Play, and Apple users use the App Store; 6. If you cannot access the app store, you can access the Binance official website download page through Yandex browser and click the official download link to get the installation package; 7. Be sure to confirm the authenticity of the website, beware of download links from non-official sources, and avoid account information leakage. The browser is only used as an access tool and does not provide application creation or download functions to ensure that

Open Yandex search engine and visit its official homepage; 2. Enter "Binance Official Website" or "Binance Official Website" in the search box to obtain accurate results; 3. Carefully identify the search results, give priority to links that are naturally ranked high, check whether the domain name is the official correct address, and avoid clicking suspicious links marked "advertising"; 4. After entering the website, verify the URL of the browser address bar immediately, confirm that there is a lock icon and the correct domain name to ensure the connection is safe; 5. Be wary of counterfeit websites, pay attention to distinguishing phishing websites that are extremely similar to the official website but have subtle spelling differences; 6. After first confirming to access the official website, use the "Add to Bookmark" function of the browser so that it can be accessed safely directly through bookmarks,

What is Treehouse(TREE)? How does Treehouse (TREE) work? Treehouse Products tETHDOR - Decentralized Quotation Rate GoNuts Points System Treehouse Highlights TREE Tokens and Token Economics Overview of the Third Quarter of 2025 Roadmap Development Team, Investors and Partners Treehouse Founding Team Investment Fund Partner Summary As DeFi continues to expand, the demand for fixed income products is growing, and its role is similar to the role of bonds in traditional financial markets. However, building on blockchain

Directory What is Zircuit How to operate Zircuit Main features of Zircuit Hybrid architecture AI security EVM compatibility security Native bridge Zircuit points Zircuit staking What is Zircuit Token (ZRC) Zircuit (ZRC) Coin Price Prediction How to buy ZRC Coin? Conclusion In recent years, the niche market of the Layer2 blockchain platform that provides services to the Ethereum (ETH) Layer1 network has flourished, mainly due to network congestion, high handling fees and poor scalability. Many of these platforms use up-volume technology, multiple transaction batches processed off-chain

1. By selecting reliable trading platforms such as Ouyi OKX or Binance to register an account, you can obtain the TRX account address for receiving assets after completing the identity verification; 2. The core elements of the TRX account include a uniquely identified account address, a private key that controls the asset and a mnemonic word that is convenient for backup. The private key and mnemonic word must be strictly confidential; 3. When using it, you must safely back up the private key and mnemonic word, be wary of phishing, conduct small-scale test transfers and regularly check account activities; 4. The TRX account can be used to manage digital assets, participate in decentralized applications, and pledge to obtain bandwidth and energy and other network resources. It is a basic tool for integrating into the TRON ecosystem. You need to pay attention to asset security throughout the process.
