
The ulimit command with the -S (soft) and -a (all) flag will display the current users soft limits. In this example, John Doe's soft limits are displayed.
[john.doe@server1 ~]# ulimit -S -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) 31119
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) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
The ulimit command with the -H (hard) and -a (all) flag will display the current users hard limits. Notice in this example that John Doe's soft limit for open files is 1024 and the hard limit is 2048.
[john.doe@server1 ~]# ulimit -S -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) 31119
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 2048
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) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Or the prlimit command can be used to list the users soft and hard limits.
[john.doe@server1 ~]# prlimit
RESOURCE DESCRIPTION SOFT HARD UNITS
AS address space limit unlimited unlimited bytes
CORE max core file size 0 unlimited bytes
CPU CPU time unlimited unlimited seconds
DATA max data size unlimited unlimited bytes
FSIZE max file size unlimited unlimited bytes
LOCKS max number of file locks held unlimited unlimited locks
MEMLOCK max locked-in-memory address space 65536 65536 bytes
MSGQUEUE max bytes in POSIX mqueues 819200 819200 bytes
NICE max nice prio allowed to raise 0 0
NOFILE max number of open files 1024 2048 files
NPROC max number of processes 4096 31665 processes
RSS max resident set size unlimited unlimited bytes
RTPRIO max real-time priority 0 0
RTTIME timeout for real-time tasks unlimited unlimited microsecs
SIGPENDING max number of pending signals 22583 22583 signals
STACK max stack size 8388608 10485760 bytes
The ulimit command followed by one of the flags listed above will return the value for only that limit. In this example, the -S and -n flags are used to only return John Doe's soft open files limit.
[john.doe@server1 ~]# ulimit -S -n
1024
A limit can temporarily be updated. In this example, John Doe's open files limit is temporarily updated to 2048. When the user signs out and then signs back into the system, the user's limits will be returned to their prior value.
[john.doe@server1 ~]# ulimit -n 2048
To permanently update a limit, you can set the limit in any of the following files
- /home/username/.bash_profile (on a Red Hat distribution - settings in this file will take precedence over similar settings in the limit.d and limits.conf files)
- /etc/security/limit.d/example.conf (settings in this file will take precedence over similar settings in the limits.conf file)
- /etc/security/limits.conf
If you want to set a limit in $HOME/.bash_profile, you will simply just have the ulimit command.
ulimit -n 2048
If you want to set a limit in a file in the limit.d directory or in the limits.conf file, the syntax is
<user|group|wildcard> <soft|hard> <item> <value>
For example
- If john.doe has more than 1024 files open (the soft limit) a warning will be appended to /var/log/messages.
- If john.doe has 2048 files open (the hard limit) john.doe will not be able to open another file
john.doe soft nofile 1024
john.doe hard nofile 2048
In this example, the limits are apply to users that are members of the "admins" group.
@admins soft nofile 1024
@admins hard nofile 2048
Wildcard can be used to apply the limit to all users except for root.
* soft nofile 1024
* hard nofile 2048
root can be used to apply limits for root.
root soft nofile 1024
root hard nofile 2048
If you make a change to the .bash_profile file, or a file in the limit.d directory, or the limits.conf file, you'll then need to disconnect and reconnect to the system for the change to take effect.
The lsof (list open files) command can be used, as the name suggests, to list the open files on the system. The lsof command without any options should return something like this. Notice in this example that many of the files have "Permission denied". This is because the lsof command in this example is being run by john.doe. Often, the lsof command is run using sudo or run as root.
[john.doe@server1 ~]$ lsof
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd unknown /proc/1/cwd (readlink: Permission denied)
init 1 root rtd unknown /proc/1/root (readlink: Permission denied)
init 1 root txt unknown /proc/1/exe (readlink: Permission denied)
init 1 root NOFD /proc/1/fd (opendir: Permission denied)
kthreadd 2 root cwd unknown /proc/2/cwd (readlink: Permission denied)
kthreadd 2 root rtd unknown /proc/2/root (readlink: Permission denied)
kthreadd 2 root txt unknown /proc/2/exe (readlink: Permission denied)
kthreadd 2 root NOFD /proc/2/fd (opendir: Permission denied)
migration 3 root cwd unknown /proc/3/cwd (readlink: Permission denied)
The lsof (list open files) command can be piped through the wc (word count) command to determine how many files are open.
[john.doe@server1 ~]$ lsof | wc -l
1234
Often, the lsof command with the -u option is used to display the files opened by a certain user.
[john.doe@server1 ~]$ lsof -u john.doe | head
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 116079 john.doe cwd unknown /proc/116079/cwd (readlink: Permission denied)
sshd 116079 john.doe rtd unknown /proc/116079/root (readlink: Permission denied)
sshd 116079 john.doe txt unknown /proc/116079/exe
Did you find this article helpful?
If so, consider buying me a coffee over at