Home » Linux » Linux Operating System: Setting resource limits with limits.conf

Linux Operating System: Setting resource limits with limits.conf

Update on:
Oct 2, 2021

Ubuntu is known as a multi-tasking, multi-process, and multiuser operating system. If the system’s all resources are used by any single process or user, other users and processes might not work in the system.

In this tutorial, I’ll show you how to set the resource limits for users and avoid such issues.

Getting ready

User account with root privileges is required.

How to do it…

Following are the steps to set the resource limits:

Check the CPU use limit with $ulimit –t.

To set new limit, open limits.conf with the following command:

[et_pb_dmb_code_snippet _builder_version=”3.0.47″ code=””][/et_pb_dmb_code_snippet]

Scroll to the end of the file and add following lines:

[et_pb_dmb_code_snippet _builder_version=”3.0.47″ code=””][/et_pb_dmb_code_snippet]

Enter Ctrl + O to save the changes.

Enter Ctrl + X to exit GNU nano editor.

How it works…

A module in a Linux system called PAM, PAM stands for pluggable authentication. The PAM module (pam_limit.so) provides the capability to set the cap for resource utilization.

You can use a Linux command ulimit to check the current limits and set the new limit using the ulimit utility. You can also set the default values of pam_limit.so using /etc/security/limits.conf.

Here, we will update limits.conf file to set a limit on CPU uses by users. As we know, we can set the limit using ulimit command but that is limited to that session only, if you want to set the limit permanently, need to configure limits.conf file.

The syntax of the limits.conf file is as follows:

[et_pb_dmb_code_snippet code=”PGRvbWFpbj4gPHR5cGU+IDxpdGVtPiA8dmFsdWU+” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f” hover_enabled=”0″ sticky_enabled=”0″]PGRvbWFpbj4gPHR5cGU+IDxpdGVtPiA8dmFsdWU+[/et_pb_dmb_code_snippet]

Here, <domain> can be a username, a group name, or a wildcard entry.

<type> denotes the type of the limit and it can have the following values:

  • soft: This is a soft limit which can be changed by user
  • hard: This is a cap on soft limit set by super user and enforced by kernel

<item> is the resource to set the limit for. You can get a list of all items with $ulimit –a:

[et_pb_dmb_code_snippet code=”JCB1bGltaXQgLWEKY29yZSBmaWxlIHNpemUgICAgICAgICAgKGJsb2NrcywgLWMpIDAKZGF0YSBzZWcgc2l6ZSAgICAgICAgICAgKGtieXRlcywgLWQpIHVubGltaXRlZApzY2hlZHVsaW5nIHByaW9yaXR5ICAgICAgICAgICAgICgtZSkgMApmaWxlIHNpemUgICAgICAgICAgICAgICAoYmxvY2tzLCAtZikgdW5saW1pdGVkCnBlbmRpbmcgc2lnbmFscyAgICAgICAgICAgICAgICAgKC1pKSAxMjA0NzgKbWF4IGxvY2tlZCBtZW1vcnkgICAgICAgKGtieXRlcywgLWwpIDY0Cm1heCBtZW1vcnkgc2l6ZSAgICAgICAgIChrYnl0ZXMsIC1tKSB1bmxpbWl0ZWQKb3BlbiBmaWxlcyAgICAgICAgICAgICAgICAgICAgICAoLW4pIDEwMjQKcGlwZSBzaXplICAgICAgICAgICAgKDUxMiBieXRlcywgLXApIDgKUE9TSVggbWVzc2FnZSBxdWV1ZXMgICAgIChieXRlcywgLXEpIDgxOTIwMApyZWFsLXRpbWUgcHJpb3JpdHkgICAgICAgICAgICAgICgtcikgMApzdGFjayBzaXplICAgICAgICAgICAgICAoa2J5dGVzLCAtcykgODE5MgpjcHUgdGltZSAgICAgICAgICAgICAgIChzZWNvbmRzLCAtdCkgdW5saW1pdGVkCm1heCB1c2VyIHByb2Nlc3NlcyAgICAgICAgICAgICAgKC11KSAxMjA0NzgKdmlydHVhbCBtZW1vcnkgICAgICAgICAgKGtieXRlcywgLXYpIHVubGltaXRlZApmaWxlIGxvY2tzICAgICAgICAgICAgICAgICAgICAgICgteCkgdW5saW1pdGVk” _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f” hover_enabled=”0″ sticky_enabled=”0″]JCB1bGltaXQgLWEKY29yZSBmaWxlIHNpemUgICAgICAgICAgKGJsb2NrcywgLWMpIDAKZGF0YSBzZWcgc2l6ZSAgICAgICAgICAgKGtieXRlcywgLWQpIHVubGltaXRlZApzY2hlZHVsaW5nIHByaW9yaXR5ICAgICAgICAgICAgICgtZSkgMApmaWxlIHNpemUgICAgICAgICAgICAgICAoYmxvY2tzLCAtZikgdW5saW1pdGVkCnBlbmRpbmcgc2lnbmFscyAgICAgICAgICAgICAgICAgKC1pKSAxMjA0NzgKbWF4IGxvY2tlZCBtZW1vcnkgICAgICAgKGtieXRlcywgLWwpIDY0Cm1heCBtZW1vcnkgc2l6ZSAgICAgICAgIChrYnl0ZXMsIC1tKSB1bmxpbWl0ZWQKb3BlbiBmaWxlcyAgICAgICAgICAgICAgICAgICAgICAoLW4pIDEwMjQKcGlwZSBzaXplICAgICAgICAgICAgKDUxMiBieXRlcywgLXApIDgKUE9TSVggbWVzc2FnZSBxdWV1ZXMgICAgIChieXRlcywgLXEpIDgxOTIwMApyZWFsLXRpbWUgcHJpb3JpdHkgICAgICAgICAgICAgICgtcikgMApzdGFjayBzaXplICAgICAgICAgICAgICAoa2J5dGVzLCAtcykgODE5MgpjcHUgdGltZSAgICAgICAgICAgICAgIChzZWNvbmRzLCAtdCkgdW5saW1pdGVkCm1heCB1c2VyIHByb2Nlc3NlcyAgICAgICAgICAgICAgKC11KSAxMjA0NzgKdmlydHVhbCBtZW1vcnkgICAgICAgICAgKGtieXRlcywgLXYpIHVubGltaXRlZApmaWxlIGxvY2tzICAgICAgICAgICAgICAgICAgICAgICgteCkgdW5saW1pdGVk[/et_pb_dmb_code_snippet]

In our example, we have set soft limit on CPU uses to 0 minutes and hard limit to 1000 minutes. You can changes soft limit values with the ulimit command. To view existing limits on open files, use the command $ulimit -n. To change limits on open files, pass the new limit as follows:

[et_pb_dmb_code_snippet code=”JHVsaW1pdCAtbiA0MDk2″ _builder_version=”4.9.4″ _module_preset=”3a2d4e4b-f2ae-4571-a284-ca584312491f” hover_enabled=”0″ sticky_enabled=”0″]JHVsaW1pdCAtbiA0MDk2[/et_pb_dmb_code_snippet]

A privileged process has authority to change either limit value but an unprivileged process having soft limit value between 0 and hard limit value, and it can be a lower hard limit value.

The command ulimit can be used to set limits on per process basis. You can’t use the ulimit command to limit resources at the user level. You can use cgroups to set a cap on resource use.

Related Posts

Creating a lame utility HTTP server in Linux Operating System

In this article, we will discuss the cURL tool in Linux. The cURL tool is used for transferring the data from or to a server. It supports many protocols, and http is one of them. cURL is used to transfer the data from URL. It has so many tricks to offer, such as http...

Finding binary dependencies in Linux Operating System

In this article, we are going to check the executable. We will find out which string is present in it by using the string command.PrerequisitesBesides having a terminal open, make sure you have a binary present in your directory.Find dependencies First, we...

Capturing network traffic headlessly in Linux Operating System

In this article, we are going to learn how to capture traffic. We are going to capture network traffic with a packet sniffer tool called tcpdump. This tool is used to filter or capture TCP/IP packets that are transferred or received over a network.PrerequisitesBesides...

Follow Us

Our Communities

More on Linux

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!



Submit a Comment

Your email address will not be published.

twenty − seven =