Linux Tricks and Techniques

For Linux Experts

Use the website for easy leaning of Linux

Thursday, 28 July 2016

How to Set Limits on User Running Processes in Linux

How to Set Limits on User Running Processes in Linux

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.

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:
You need root access to your system to modify the user limits
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. 


No comments:
Write comments