In this tutorial for beginners you will get to know the ulimit team under Linux. You will learn how to use it to control the allocation of system resources.
What is ulimit in Linux?
Ulimit is a built-in shell command to display, assign and limit resources. It is very important for any system to regulate this type of control.
This type of control can be applied at global, group and user level. It not only ensures a smooth workflow, but also prevents unwanted processes from absorbing system resources such as RAM and processor power.
Ulimit is linked to a security configuration file. Your exact location may vary, but it’s usually something like /etc/security/limits.conf. With Ulimit we can quickly change this configuration.
Soft versus hard limit
As a user, you can actually configure the UV radiation parameters. You can try these out Linux Server Support.
You may be wondering why you need to set a limit when the user can configure it. Here come the soft and hard boundaries.
So, from an administrator’s point of view, you may prefer to keep your user at a certain value. That would be your soft limit (say 25).
You can then set a strict limit that cannot be exceeded by this user (50). The user may increase his limit from 25 to 50.
Using ulimit under Linux
Here is the syntax of ulimit:
Show all restrictions for each user
This way you can display all kinds of restrictions for the specified user:
ulimit is a username
The -a flag indicates all options and their configuration for your specific username.
If you omit the username, the restrictions will be displayed. I’ll show you the boundaries I’ve set for myself:
[email protected] directory:~$ ulimit -a Kernel file size (blocks, -c) 0Data segment size (kByte, -d) unlimited scheduling priority (-e) 0File size (blocks), -(-i) 31503max. locked memory size (kByte, -l) 65536max. Locked memory (kByte, -m) unlimited pipe size (s) 1024 pipe size (512 bytes), -p) 8 POSIX message queues (Byte, -q) 819200Realtime priority (-r) 0 Stack size (bytes), (-s) 8192 CPU time (seconds, -t) unlimited maximum time of user processes (-u) 31503 virtual memory (byte, -v) unlimited file lock (-x) unlimited file lock (-x) virtual memory
Of course, your defaults can be different from mine. This view displays the description, the assigned tag (which allows you to change restrictions) and the configuration.
Limitations of hard and soft display
You can also see the boundaries of each of these respective flags.
Use the -S option to display soft restrictions:
Use the -H option to display strict restrictions:
It is more useful to combine them with specific flags from above. If you want to check the strict limit of the maximum number of custom processes, you must enter this:
[email protected] manual: ~$ ulimit -Hu
Change in limit value (temporary)
Let’s change this value to 31500 for demonstration purposes and check the strict limit again.
Please note that the changes allowed by your personal account are only temporary and will affect your current shell.
To confirm this, I came out of my shell, created a new terminal and got the initial default value.
[email protected] manual: ~$ ulimit -Hu
The following section explains how to make the changes permanent.
Constant change on the road
As I said at the beginning of this article, ulimit is controlled by /etc/security/limits.conf. If you want to constantly change a user’s limits, you need to change the security file as root.
You must include these four elements in your assembly:
Here is the text I have attached to the file to strictly limit the number of processes for the user christoper (i.e. my own account)
Christopher Hard Nprok 2000
Don’t forget that you can only activate the main account if you are fully aware of the possible consequences. I did it in a virtual machine so you don’t have to do it yourself.
[email protected] manual:~$ su
[email protected] manual:/home/christopher# nano /etc/security/limits.conf
[email protected] manual:/home/christopher# exit
[email protected] manual:~$ ulimit -u
As you can see, Christopher changed the limit to 20,000.
How do I know which keyword to use to change /etc/security/limits.conf? Here is a table with the possible keywords of the elements and their descriptions:
|Keyword for item||Description|
|Main location||limits the kernel size of the file (KB)|
|Data||maximum data size(KB)|
|Electronic mail||maximum file size (QB)|
|Memo||maximum space for address locking in memory (KB)|
|Profile||maximum descriptors of open files|
|rss||maximum size of the living room kit (RK)|
|Stack||maximum stack size|
|Corrigendum||maximum processor time|
|nproc||maximum number of processes|
|in the form of||Address limit|
|maxlogs||maximum number of connections for this user|
|Priority||Start priority of the user process with|
|blocks||the maximum number of file blocks a user can hold|
|msgqueue||– the maximum amount of memory used by the POSIX message queues (bytes).|
|good website||Maximum priority that can be increased to the level of the values : [-20, 19]|
|rtprio||first priority real-time|
|chroot||change the root to a directory (Debian-specific)|
|Type of limit value||Description|
|–||hard and soft limit|
Amendment of the upper limit for groups
Changing the group policy is similar to what you saw in the previous section, but you activate the @ symbol in front of the group name.
Here is an example where I set the maximum number of connections for a student in the group to 4 by editing the /etc/security/limits.conf file:
Pupils – max. 4
I hope you enjoyed this quick introduction to ulimit Linux.
If you have any comments or questions, please leave them below. If you have suggestions for topics you would like to see highlighted, feel free to leave them behind.
Christopher is a software developer in Orlando, Florida. He likes open source, Taco Bell and Chi-weeney named Max. Visit his website for more information or contact him via social media.
Did you like the article? Share with us and help us grow ?how to check the ulimit value for a user in linux,ulimit redhat