VOOZH about

URL: https://www.tecmint.com/set-limits-on-user-processes-using-ulimit-in-linux/

⇱ How to Set Limits for User Running Processes in Linux


Skip to content

One of the Linux’s beauties is that you can control almost everything about it. This gives a system administrator a great control over his system and better utilization of the system resources.

While some might have never thought about doing this, it is important to know that in Linux you can limit how much resource a single user may use and for how long.

Read Also: How to Increase Number of Open Files Limit in Linux

In this short topic, we will show you how to limit the number of processes started by user and how to check the current limits and modify them.

Before we go any further there are two things we need to point:

  1. You need root access to your system to modify the user limits
  2. You must be extremely careful if you plan to modify these limits

To setup user limits, we will need to edit the following file:

/etc/security/limits.conf

This file is used to apply ulimit created by the pam_module

The file has the following syntax:

<domain> <type> <item> <value>

Here we will stop to discuss each of the options:

  • Domain – this includes usernames, groups, guid ranges etc
  • Type – soft and hard limits
  • Item – the item that will be limited – core size, file size,  nproc etc
  • Value – this is the value for the given limit

A good sample for a limit is:

@student          hard           nproc                20

The above line sets a hard limit of maximum 20 processes on the "student" group.

If you want to see the limits of a certain process has you can simply “cat” the limits file like this:

# cat /proc/PID/limits

Where PID is the actual process ID, you can find out process id by using ps command. For more detailed explanation, read our article that says – Find Running Linux Processes and Set Process Limits Per-User Level

So here is an example:

# cat /proc/2497/limits
Sample Output
Limit Soft Limit Hard Limit Units 
Max cpu time unlimited unlimited seconds 
Max file size unlimited unlimited bytes 
Max data size unlimited unlimited bytes 
Max stack size 8388608 unlimited bytes 
Max core file size 0 unlimited bytes 
Max resident set unlimited unlimited bytes 
Max processes 32042 32042 processes 
Max open files 1024 4096 files 
Max locked memory 65536 65536 bytes 
Max address space unlimited unlimited bytes 
Max file locks unlimited unlimited locks 
Max pending signals 32042 32042 signals 
Max msgqueue size 819200 819200 bytes 
Max nice priority 0 0 
Max realtime priority 0 0 
Max realtime timeout unlimited unlimited us 

All of the lines are pretty much self explanatory. However if you want to find more the settings you can input in limits.conf file, you can have a look at the manual provided here.

If you have any questions or comments, please do not hesitate to submit them in the comment section below.

If this article helped, share it with someone on your team.
TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Marin Todorov
I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

7 Comments

Leave a Reply
  1. Hi, why it should be 16384 only? even i have same issue. I tried with 4096 it is not resolving the issue.

    Reply
  2. I am able to change the nproc for additional users using /etc/security/limits.conf but some how root users nproc value set is 150. When logged as root and execute ulimit -n I get the value 150.

    How can I change root users nproc value?

    Reply
    • @Deepa,

      The system wide configuration file /etc/security/limits.d/90-nproc.conf (RHEL6) and /etc/security/limits.d/20-nproc.conf (RHEL7) specifies the default nproc limits as:

      * soft nproc 1024
      root soft nproc unlimited
      
      Reply
      • Thank you, We are Using RHEL 6. Checked the /etc/limits. d/90-nproc.conf this file has same values as you mentioned. However when I run ulimit – u as root or any other user get value 150.

        In file /etc/security/limits.conf file I commented line * hard nproc 150 which was there before. I logged out restarted httpd still same value is coming. How reset default nproc value for root and other users. Please help

        Reply
  3. Hi,

    Thanks a lot.

    Reply
  4. Can you actually see what processes are being executed? Share those with so we can have a better understanding of the issue. Also my suggestion is to check the IO utilisation as well

    Reply
  5. Hi Ravi,

    I am facing the issue with oracle user, user complains for slowness in Apache. while slowness issue I am not able to login with oracle users. It is giving error like resources are in use. Every time i have to restart my network services. I have set my oracle user limits in /etc/security/limits.conf as oracle soft nproc 16384
    oracle hard nproc 16384
    oracle soft nofile 4096
    oracle hard nofile 65536
    oracle soft stack 10240.

    Please share if you can help me.

    Reply

Got Something to Say? Join the Discussion... Cancel reply

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Check your email for a magic link to get started.