153
votes
Accepted
How to set ulimits on service with systemd?
The mappings of systemd limits to ulimit
Directive ulimit equivalent Unit
LimitCPU= ulimit -t Seconds
LimitFSIZE= ulimit -f Bytes
LimitDATA= ...
139
votes
Limit memory usage for a single Linux process
On any systemd-based distro you can also use cgroups indirectly through systemd-run. E.g. for your case of limiting pdftoppm to 500M of RAM, starting with cgroupsv2, you can simply do:
systemd-run --...
89
votes
Accepted
Why can't I crash my system with a fork bomb?
You probably have a Linux distro that uses systemd.
Systemd creates a cgroup for each user, and all processes of a user belong to the same cgroup.
Cgroups is a Linux mechanism to set limits on ...
58
votes
Modify ulimit (open files) of a specific process
To change the limits of a running process, you may use the utility command prlimit.
prlimit --pid 12345 --nofile=1024:1024
What that does internally is to call setrlimit(2). The man page of prlimit ...
28
votes
How to check ulimit usage
Output the current user's percentage of open files, proc, and pending signals, by several inconvenient methods and standard tools:
paste <(grep 'open files\|processes\|pending signals' \
...
28
votes
How calculate the number of files which can be passed as arguments to some command for batch processing?
Let xargs do the calculation for you.
printf '%s\0' files/* | xargs -0 mv -t new_files_dir
26
votes
Accepted
sudo: setrlimit(RLIMIT_CORE): Operation not permitted
a fix has been applied to sudo 1.8.31p1 and is already in 1.9 however this warning has a work around ... just issue
echo "Set disable_coredump false" >> /etc/sudo.conf
for details see https://...
22
votes
Understanding the differences between pid_max, ulimit -u and thread_max
Sorry, the accepted answer is bad information on several fronts.
/proc/sys/kernel/pid_max has nothing to do with the maximum number of processes that can be run at any given time. It is, in fact, the ...
22
votes
Accepted
/etc/security/limits.conf not applied
https://superuser.com/questions/1200539/cannot-increase-open-file-limit-past-4096-ubuntu/1200818#_=_
There's a bug since Ubuntu 16 apparently.
Basically:
Edit /etc/systemd/user.conf for the soft ...
17
votes
How can I increase open files limit for all processes?
But if you're trying to increase the max number of open files of a service like MariaDB or something else (using systemd) you have to do directly in file .service
/lib/systemd/system/<servicename&...
16
votes
Why can't I crash my system with a fork bomb?
This won't crash modern Linux systems anymore anyway.
It creates hoards of processes but doesn't really burn all that much CPU as the processes go idle. You run out of slots in the process table ...
15
votes
/etc/security/limits.conf not applied
It is recommended to create /etc/systemd/*.d/ directories instead of editing /etc/systemd/system.conf and /etc/systemd/user.conf directly.
Create a new file /etc/systemd/system.conf.d/limits.conf ...
14
votes
How to Throttle per process I/O to a max limit?
The answer of fche is a very good hint, thanks for that, although it dosn't really solve the problem cause the question was to limit a process to a specific bandwidth.
I would suggest something like ...
13
votes
Accepted
What's the difference between setting open file limits in /etc/sysctl.conf vs /etc/security/limits.conf?
The difference is the scope, and how it's applied. Open file limits set via sysctls apply to the entire system, whereas limits set via /etc/security/limits.conf apply only to things that meet the ...
13
votes
ulimit vs file-max
ulimit shows the per-process maximum. The two files under /proc shows system-wide numbers.
From ServerFault:
file-max is the maximum File Descriptors (FD) enforced on a kernel level, which cannot be ...
13
votes
Meaning of the values for ulimit memlock flag
Yes you are right. Check the definition of memlock here
memlock
maximum locked-in-memory address space (KB)
This is memory that will not be paged out. It is frequently used by
database management ...
12
votes
Accepted
Does nproc in limits.conf refers to number of processes or number of threads?
On Linux it refers to the number of threads. From setrlimit(2) (which is the system call used to set the limits):
RLIMIT_NPROC
The maximum number of processes (or, more precisely on Linux, ...
12
votes
Accepted
Fixing ulimit: open files: cannot modify limit: Operation not permitted
Check that /etc/ssh/sshd_config contains:
UsePAM=yes
and that /etc/pam.d/sshd contains:
session required pam_limits.so
In the comment below @venimus states the 1M limit is hardcoded:
The ...
11
votes
Systemd LimitNOFILE capped to 4096
Late answer;
limits.conf is not used when systemd is running (limits.conf is for non-systemd systems).
The file you actually want is; /etc/systemd/system.conf - this is the global config. Then you ...
10
votes
Accepted
Why does a ulimit -u far greater than the number of processes I'm running cause problems?
On Linux threads count towards the ulimit -u count, but they don't show up normally with ps -A. You need to add the L flag.
eg on my machine:
% ps -A | wc -l
124
% ps -AL | wc -l
155
We can see ...
10
votes
Accepted
How to cause "Argument list too long" error?
Using getconf ARG_MAX to generate a long list of x and calling an external utility with that as its argument would generate an "Argument list too long" error:
$ /bin/echo $( perl -e 'print "x" x $...
10
votes
Accepted
Change the resource limits (ulimit / rlimit) of a running process
I've figured it out.
On some kernels (e.g. 2.6.32+), at least on CentOS/RHEL, you can change the resource limits of a running process using /proc/<pid>/limits, e.g.:
$ grep "open files" /proc/...
9
votes
How to persistently control maximum system resource consumption on Mac?
System limits
Changing the limits in /etc/launchd.conf or /etc/rc.local is no longer supported for the recent macOS. See: Old Systems and Technology.
Instead, you should create a new launch agent.
...
9
votes
Why does the following way not change core file limit size?
According to the manpage, ulimit "provides control over the resources available to the shell and to processes started by it". So the ulimit value is valid for the current shell.
You are invoking ...
9
votes
Why can't I crash my system with a fork bomb?
Back in the 90's I accidentally unleashed one of these on myself. I had inadvertently set the execute bit on a C source file that had a fork() command in it. When I double-clicked it, csh tried to run ...
9
votes
Accepted
Chromium browser: exceed data ulimit
Why does chromium have different limits than all other programs?
Chromium may look like a simple application but it is not, first there is the multi-threading which makes chromium run multiple ...
9
votes
Accepted
Can't set ulimit -n like I want to
# ulimit -n 1048576
# ulimit -n 2000000
bash: ulimit: open files: cannot modify limit: Operation not permitted
# sysctl fs.nr_open
fs.nr_open = 1048576
# sysctl fs.nr_open=2000000
fs.nr_open = 2000000
...
8
votes
do changes in /etc/security/limits.conf require a reboot?
To quote @Tombart's answer
These limits will be applied after reboot.
If you want to apply changes without reboot, modify
/etc/pam.d/common-session by adding this line at the end of file:
...
8
votes
Accepted
About ulimit/setrlimit and cgroup
All limits apply independently. When a process makes a request that would require going over some limit, the request is denied. This holds whether the limit is for a cgroup, per process, or per user.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
ulimit × 201linux × 62
limit × 38
process × 16
rhel × 15
memory × 15
ubuntu × 14
file-descriptors × 13
bash × 12
open-files × 12
centos × 10
resources × 10
systemd × 9
core-dump × 9
security × 8
files × 7
docker × 7
solaris × 7
shell × 6
ssh × 6
pam × 6
macos × 6
sysctl × 6
debian × 5
kernel × 5