Cyberithub

33 Practical Examples of ulimit command in Linux/Unix for Professionals

Table of Contents

Advertisements

In this article, I will take you through 33 Practical Examples of ulimit command in Linux/Unix. If you want to limit the system resources for a User in your Linux/Unix based Server then you need to use ulimit command. There are two types of limits one can put in a system: hard limit and soft limit. You can check the configuration in /etc/security/limits.conf where usually hard limit is set by the root user and soft limit can be overridden by another user.

Now you might think what is hard limit and what is soft limit ? Hard limit and soft limit is a mechanism through which you can limit the System resources for a User in the Server. Soft limit is the limit after which you will start getting warning about your over usages of the resources till you reach the hard limit. Hard limit is the limit after which you will not be allowed to use system resources any further. Below are the parameters which can be set through ulimit command.

core - limits the core file size (KB)
data - max data size (KB)
fsize - maximum filesize (KB)
memlock - max locked-in-memory address space (KB)
nofile - max number of open file descriptors
rss - max resident set size (KB)
stack - max stack size (KB)
cpu - max CPU time (MIN)
nproc - max number of processes
as - address space limit (KB)
maxlogins - max number of logins for this user
maxsyslogins - max number of logins on the system
priority - the priority to run user process with
locks - max number of file locks the user can hold
sigpending - max number of pending signals
msgqueue - max memory used by POSIX message queues (bytes)
nice - max nice priority allowed to raise to values: [-20, 19]
rtprio - max realtime priority

33 Practical Examples of ulimit command in Linux/Unix for Professionals 1

Examples of ulimit command in Linux/Unix

Also Read: How to Drop/Flush/Clear Cache Memory or RAM in Linux (RedHat/CentOS 7/8) in 6 Best Steps

Example 1: How to check the core file size limit in Linux/Unix

If you want to check the core file size limit then you need to use ulimit -c command as shown below. As you can see from below output current core file size limit is set to 0 blocks.

[root@localhost ~]# ulimit -c
0

-c : core file size in blocks. Check ulimit command man page for more info.

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

Example 2: How to change the core file size limit in Linux/Unix

If you want to change the core file size limit then you need to use -c option with ulimit command as shown below. In this example we are trying to change the core file size limit to 10 blocks using ulimit -c 10 command.

[root@localhost ~]# ulimit -c 10

Now if you check the core file size limit again using ulimit -c command then you can see the new set value as 10.

[root@localhost ~]# ulimit -c
10

NOTE:

Please note that any changes done through ulimit command from CLI will be only a temporary change and will not work once the session ends or system got rebooted. To make the resource limit settings permanent you need to set it using /etc/settings/limits.conf file.

Example 3: How to check the data segment size limit in Linux/Unix

If you want to check the data segment size limit then you need to use ulimit -d command as shown below. As you can see from below output, current data segment size limit is set to  unlimited kbytes.

[root@localhost ~]# ulimit -d
unlimited

-d : data seg size in kbytes. Check ulimit command man page for more info.

NOTE:

Please be very careful before changing any of the System resource limits using ulimit command as giving incorrect values can sometime becomes disastrous for your Production Servers.

Example 4: How to change the data segment size limit in Linux/Unix

If you want to change the data segment size limit then you need to use -d option with ulimit command as shown below. In this example, we are trying to change the data segment size limit to 100 kbytes using ulimit -d 100 command.

[root@localhost ~]# ulimit -d 100

Now if you check the data segment size limit again using ulimit -d command then you can see the new set value as 100.

[root@localhost ~]# ulimit -d
100

Example 5: How to check the Scheduling Priority limit in Linux/Unix

If you want to check the Scheduling Priority Limit then you need to use ulimit -e command as shown below. As you can see from below output, current scheduling priority is set to 0.

[root@localhost ~]# ulimit -e
0

-e : scheduling priority. Check ulimit command man page for more info.

Example 6: How to change the Scheduling Priority limit in Linux/Unix

If you want to change the scheduling priority limit then you need to use -e option with ulimit command as shown below. In this example, we are trying to change the scheduling priority limit to 1 by using ulimit -e 1 command.

[root@localhost ~]# ulimit -e 1

Now if you check the scheduling priority limit again using ulimit -e command then you can see the new set value as 1.

[root@localhost ~]# ulimit -e
1

Example 7: How to check the File Size limit in Linux/Unix

If you want to check the file size limit then you need to use ulimit -f command as shown below. As you can see from below output, current file size limit is set to unlimited blocks.

[root@localhost ~]# ulimit -f
unlimited

-f : file size in blocks. Check ulimit command man page for more info.

NOTE:

Please note that all the parameter values I have used in this article are random values and are used only for example purposes. It may not work correctly in your system hence you need to use ulimit values as per your System resource Limits.

Example 8: How to change the File Size Limit in Linux/Unix

If you want to change the file size then you need to use -f option with ulimit command as shown below. In this example, we are trying to change the file size limit to 100 blocks using ulimit -f 100 command.

[root@localhost ~]# ulimit -f 100

Now if you check the file size limit again using ulimit -f command then you can see the new set value as 100.

[root@localhost ~]# ulimit -f
100

Example 9: How to check the No of Pending Signals limit in Linux

If you want to check number of pending signals limit then you need to use ulimit -i command as shown below. As you can see from below output, current pending signals is set to 11099.

[root@localhost ~]# ulimit -i
11099

-i : pending signals. Check ulimit command man page for more info.

Example 10: How to change the no of Pending Signals limit in Linux

If you want to change the number of pending signals limit then you need to use -i option with ulimit command as shown below. In this example, we are trying to change the number of pending signals to 9 using ulimit -i 9 command.

[root@localhost ~]# ulimit -i 9

Now if you check the pending signals again using ulimit -i command then you can see the new set value as 9.

[root@localhost ~]# ulimit -i
9

Example 11: How to check Open files limit in Linux/Unix

If you want to check the open files limit then you need to use ulimit -n command as shown below. As you can see from below output, current open files limit is set to 1024.

[root@localhost ~]# ulimit -n
1024

-n : open files. Check ulimit command man page for more info.

Example 12: How to change Open Files limit in Linux/Unix

If you want to change the open files limit then you need to use -n option with ulimit command as shown below. In this example, we are trying to change the open files limit to 800 using ulimit -n 800 command.

[root@localhost ~]# ulimit -n 800

Now if you check the open files limit again using ulimit -n command then you can see the new set value as 800.

[root@localhost ~]# ulimit -n
800

Example 13: How to check the pipe size limit using ulimit command in Linux/Unix

If you want to check the pipe size limit then you need to use ulimit -p command as shown below. As you can see from below output, current pipe size limit is set to 8.

[root@localhost ~]# ulimit -p
8

-p : pipe size in 512 bytes. Check ulimit command man page for more info.

Example 14: How to check max memory size limit using ulimit command in Linux

If you want to check max locked memory limits then you need to use ulimit -m command as shown below. As you can see from below output, current max locked memory limits is set to unlimited kbytes.

[root@localhost ~]# ulimit -m
unlimited

-m : max memory size in kbytes. Check ulimit command man page for more info.

Example 15: How to check POSIX messages queue limit in Linux

If you want to check POSIX messages queue limit then you need to use ulimit -q command as shown below. As you can see from below output, current POSIX messages queue limit is set to 819200.

[root@localhost ~]# ulimit -q
819200

-q : POSIX message queue in bytes. Check ulimit command man page for more info.

Example 16: How to change POSIX messages queue limit in Linux

If you want to change POSIX messages queue limit then you need to use -q option with ulimit command as shown below. In this example, we are trying to change the POSIX messages queue limit to 900000 using ulimit -q 900000 command.

[root@localhost ~]# ulimit -q 900000

Now if you check the POSIX messages queue limit again using ulimit -q command then you can see the new set value as 900000.

[root@localhost ~]# ulimit -q
900000

Example 17: How to check real-time priority limit in Linux

If you want to check real-time priority limit value then you need to use ulimit -r command as shown below. As you can see from below output, current real-time priority limit is set to 0.

[root@localhost ~]# ulimit -r
0

-r : real-time priority. Check ulimit command man page for more info.

Example 18: How to change real-time priority limit in Linux

If you want to change real-time priority limit then you need to use -r option with ulimit command as shown below. In this example, we are trying to change real-time priority limit to 5 using ulimit -r 5 command.

[root@localhost ~]# ulimit -r 5

Now if you check the real-time priority limit again using ulimit -r command then you can see the new set value as 5.

[root@localhost ~]# ulimit -r
5

Example 19: How to check stack size limit in Linux/Unix

If you want to check stack size limit then you need to use ulimit -s command as shown below. As you can see from below output, current stack size limit is set to 8192 kbytes.

[root@localhost ~]# ulimit -s
8192

-s : stack size in kbytes. Check ulimit command man page for more info.

Example 20: How to change stack size limit in Linux/Unix

If you want to change stack size limit then you need to use -s option with ulimit command as shown below. In this example, we are trying to change the stack size limit to 9000 kbytes using ulimit -s 9000 command.

[root@localhost ~]# ulimit -s 9000

Now if you check the stack size limit again using ulimit -s command then you can see the new set value as 9000.

[root@localhost ~]# ulimit -s
9000

Example 21: How to check CPU time limit in Linux/Unix

If you want to check the CPU time limit then you need to use ulimit -t command as shown below. As you can see from below output, current CPU time limit is set to unlimited seconds.

[root@localhost ~]# ulimit -t
unlimited

-t : cpu time in seconds. Check ulimit command man page for more info.

Example 22: How to change CPU time limit in Linux/Unix

If you want to change the CPU time limit then you need to use -t option with ulimit command as shown below. In this example we are trying to change the cpu time limit to 6 secs using ulimit -t 6 command.

[root@localhost ~]# ulimit -t 6

Now if you check the CPU time limit again using ulimit -t command then you can see the new set value as 6.

[root@localhost ~]# ulimit -t
6

Example 23: How to check max user processes limit in Linux/Unix

If you want to check max user processes limit then you need to use ulimit -u command as shown below. As you can see from below output, current max use processes limit is set to 11099.

[root@localhost ~]# ulimit -u
11099

-u : max user processes. Check ulimit command man page for more info.

Example 24: How to change max user processes limit in Linux/Unix

If you want to change the max user processes limit then you need to use -u option with ulimit command as shown below. In this example, we are trying to change the max user processes limit to 12000 using ulimit -u 12000 command.

[root@localhost ~]# ulimit -u 12000

Now if you check the max user processes limit again using ulimit -u command then you can see the new set value as 12000.

[root@localhost ~]# ulimit -u
12000

Example 25: How to check virtual memory limit in Linux/Unix

If you want to check virtual memory limit then you need to use ulimit -v command as shown below. As you can see from below output, current virtual memory limit is set to unlimited.

[root@localhost ~]# ulimit -v
unlimited

Example 26: How to change virtual memory limit in Linux/Unix

If you want to change the virtual memory limit then you need to use -v option with ulimit command as shown below. In this example, we are trying to change virtual memory limit to 5000 kbytes then you need to use ulimit -v 5000 command.

[root@localhost ~]# ulimit -v 5000

-v : virtual memory in kbytes

Now if you check the virtual memory limit again using ulimit -v command then you can see the new set value as 5000.

[root@localhost ~]# ulimit -v
5000

Example 27: How to check File Lock Limits in Linux

If you want to check File lock limits then you need to use ulimit -x command as shown below. As you can see from below output, currently file lock limits is set to unlimited.

[root@localhost ~]# ulimit -x
unlimited

-x : file locks

Example 28: How to change File Lock Limits in Linux

If you want to change File Lock Limits then you need to use -x option with ulimit command as shown below. In this example we are trying to change the file lock limits to 100 using ulimit -x 100 command.

[root@localhost ~]# ulimit -x 100

Now if you check the core file lock limit again using ulimit -x command then you can see the new set value as 100.

[root@localhost ~]# ulimit -x
100

Example 29: How to check max locked memory limits in Linux

If you want to check max locked memory limits then you need to use ulimit -l command as shown below. As you can see from below output, current max locked memory limits is set to unlimited kbytes.

[root@localhost ~]# ulimit -l
unlimited

-l : max locked memory in kbytes. Check ulimit command man page for more info.

Example 30: How to change max locked memory limits in Linux

If you want to change max locked memory limits then you need to use -l option with ulimit command as shown below. In this example, we are trying to change locked memory limits to 1000 kbytes using ulimit -l 1000 command.

[root@localhost ~]# ulimit -l 1000

Now if you check the max locked memory limit again using ulimit -l command then you can see the new set value as 1000.

[root@localhost ~]# ulimit -l
1000

Example 31: How to change max memory size limits in Linux

If you want to change max memory size limits then you need to use -m option with ulimit command as shown below. In this example, we are trying to change max memory size limits to 1000 using ulimit -m 1000 command.

[root@localhost ~]# ulimit -m 1000

Now if you check the max memory size limits again using ulimit -m command then you can see the new set value as 1000.

[root@localhost ~]# ulimit -m
1000

Example 32: How to check ulimit configuration in Linux

If you want to check your current ulimit settings then you need to use ulimit -a command as shown below.

[root@localhost ~]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 11099
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 11099
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

-a : display current ulimit settings. Check ulimit command man page for more info.

Example 33: How to change ulimit values permanently

If you want to change any of the system resource limits permanently then you need to edit the  /etc/security/limits.conf file and provide the values as shown below.

[root@localhost ~]# vi /etc/security/limits.conf
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain> <type> <item> <value>
#
#Where:
#<domain> can be:
# - a user name
# - a group name, with @group syntax
# - the wildcard *, for default entry
# - the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
#
#<item> can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open file descriptors
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit (KB)
# - maxlogins - max number of logins for this user
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-20, 19]
# - rtprio - max realtime priority
#
#<domain> <type> <item> <value>
#

#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4

# End of file

 

 

Popular Recommendations:-

10 Popular modprobe command examples in Linux/Unix (View,Install and Remove Modules)

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)

9 useful w command in Linux with Examples

12 Most Popular rm command in Linux with Examples

6 Populat stat command in Linux/Unix for Beginners

11 Useful PSSH Command Examples to Perform Parallel SSH in Multiple Linux Servers

Unix ulimit command man page

20 Popular Examples of cat command in Linux/Unix for Beginners

1 thought on “33 Practical Examples of ulimit command in Linux/Unix for Professionals”

Leave a Comment