There can be more than one user on a single machine. Available system resources can be bypassed by a single user (voluntarily or unintentionally). Such a situation could create problems for all other users of the system. To avoid this, we need to create restrictions for users to only get what they need. The Linux ulimit command allows us to limit the available system resources for different users. This command could help in allocating resources as per requirements in the most appropriate way.
In this article, we will provide you with multiple illustrations to understand the implementation of the ulimit command on Linux.
Example #1: Using the ulimit Command to Find Resources Available to the Current User
The first and basic use of the ulimit command would be projected in this example. We will discover the availability status of Linux resources for the currently logged in user.
Start the terminal and type the following command to get the limit for the current consumer.
Press the Enter key to find the output.
As the output shows, the currently logged on user has unlimited access to the resources.
Example #2: Finding the detailed accessibility of the resource
for the currently connected consumer
The example above finds us the limit available for user resources, but does not provide us with the details of the resources that are accessible. To verify the details of all the resources
available to the user, we must write -a with the ulimit send. This will give us access to all the resources available to today’s consumers. If you want to locate the details of the resources available to the user other than the currently logged on user, you must provide the user name after the -a flag. At the moment, we are finding it for the current user, so we don’t need to type a username.
After executing the command, we will be provided with a list of resources and the limit available to the currently logged in Linux user. In addition, it has provided us with several flags that can be supplied with the ulimit command to find the limit for a specific resource.
We’ll practice some of these commands here.
If you want to check the available limit of the main file size for the
current user, you need to enter this command:
The result tells us that the available limit of the main file size for the Linux user is 0
.
We can limit this file size by giving a limit value with the -c flag.
Now, the available limit of the main file size for the current consumer is restricted to 10.
To check the size of the data, use the -d flag with the ulimit command.
Now, we will alter this limit.
We will find the file size with flag –
f, the pipe size with flag -p and the maximum user process with -u running these commands one by one in the terminal.
To check the file size limit, type the command: The user limit for
pipe size can be checked using this
command:
You can get the maximum user process by using the following command:
Similarly, you can find any of the resource availability for the current user individually using the appropriate indicator for that particular resource.
Soft
limits and hard limits in Linux Limits in Linux
are divided into two categories: soft limits and hard limits. Strict limits are limits set only by the root user for all other users. Whereas, soft limits are limits that any user can change using the ulimit command, but they can only be adjusted up to the maximum limit set by the root user.
Example #3: Using
the ulimit command to find the hard limit
We can display the strict limit values for the user who is currently logged in using the -H flag with the ulimit command. To do this we need to write the following command in the terminal:
The output shows the strict limit value set by the root user for the current Linux user
.
We can also combine the flags mentioned above with the -H flag to find the boundary for a specific resource. We’ll practice some of the commands here.
To find the hard limit for the stack size,
we need to type the following command in the terminal: To check the
hard limit for
the pipe size, combine -H and -p
.
This command might get a
maximum limit for the maximum memory size: Similarly, you can find the hard limit for
any of the system resources
for the current user.
Example #4: Using the ulimit command to
find the soft limit
In addition to checking the strict limits for the user, you can also find out the soft limits. To check the soft limit, the flag to use is -S with the ulimit command.
Executing the command will give us the soft limit for the currently logged in Linux user.
Similarly, with the
hard limit, we can also find the soft limit for a specific system resource by giving the appropriate flag combined with the -S flag along with the ulimit command.
To get the soft limit for
open files, we will run the following
command: The soft
limit for pending signals can be acquired using this command:
In the same way, you can find all other soft limits for any of the required system resources for a specific user.
Conclusion
You have learned how to use the ulimit of Linux in this tutorial. We have discussed the basic use of the ulimit command, as well as the flags that are available to directly find the individual resource available to the current user. In addition, both types of limits have been practiced in this guide. The combination of soft and hard limits with other flags is explained with the practical implementation in Linux.