Skip to main content
155 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 --...
Hi-Angel's user avatar
  • 5,600
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 ...
Hkoof's user avatar
  • 1,687
59 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 ...
user7610's user avatar
  • 2,198
31 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' \ ...
agc's user avatar
  • 7,393
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
Gilles 'SO- stop being evil''s user avatar
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://...
John Scott Stensland's user avatar
17 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 ...
Marc.2377's user avatar
  • 1,202
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 ...
Joshua's user avatar
  • 1,965
15 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 ...
vishnu viswanath's user avatar
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 ...
Benibr's user avatar
  • 267
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 ...
Kusalananda's user avatar
  • 356k
12 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 ...
SiNGH's user avatar
  • 121
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 $...
Kusalananda's user avatar
  • 356k
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/...
Bart's user avatar
  • 2,314
10 votes
Accepted

ulimit for stack size - per process or per thread limit?

SUMMARY For the main thread, you have to call setrlimit() (perhaps by using ulimit) before the process is started in order to ensure the larger stack size is effective. For threads started by the ...
Andrew Henle's user avatar
  • 4,008
10 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 ...
ilkkachu's user avatar
  • 148k
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 ...
dr_'s user avatar
  • 32.4k
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 ...
T.E.D.'s user avatar
  • 291
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 process ...
intika's user avatar
  • 15.1k
8 votes
Accepted

Is setting ulimit -v sufficient to avoid memory leak

Some description about how ulimit works: ulimit has deal with setrlimit and getrlimit system calls. It's easy to ensure by strace-ing of bash process (ulimit is component of the bash). I set 1024kb ...
Yurij Goncharuk's user avatar
8 votes

How to cause "Argument list too long" error?

On many Linux distributions, you can find out what's the current value of ARG_MAX by running getconf ARG_MAX A simple way to generate the message "Argument list too long" is to actually supply a long ...
AlexP's user avatar
  • 10.8k
7 votes

Limit memory usage for a single Linux process

While this isn't what the OP originally asked for, but for the sake of completeness, for processes that are already running, I use prlimit E.G. $ prlimit -v1073741824 -pid <xx> Sets the max ...
0xc0de's user avatar
  • 345
7 votes

Limit memory usage for a single Linux process

cgroupsv2 update (Ubuntu 22.04 - 24.10) Things have moved around a bit. Compared to https://unix.stackexchange.com/a/125024/32558 now you now need: sudo apt install cgroup-tools sudo cgcreate -a $USER:...
Ciro Santilli OurBigBook.com's user avatar
7 votes

How to increase the maximum number of open files on Fedora?

The problem here is that the GUI (and gnome-terminal) are started by systemd --user, which does not read from /etc/security/limits.conf. Instead, you should edit /etc/systemd/user.conf and /etc/...
tao_oat's user avatar
  • 171
7 votes
Accepted

Figure out which process forks too many threads

ps -eo nlwp,pid,args --sort nlwp Would show a list of processes sorted by their number of threads. For a top-like view of that, you can always do: watch -n 1 'ps -eo nlwp,pid,args --sort -nlwp | ...
Stéphane Chazelas's user avatar
7 votes

Enabling core files on CentOS 8.1

Your core dumps are probably in /var/lib/systemd/coredump (unless you've changed your systemd configuration to put them somewhere else). Use coredumpctl list to see what core dumps are available, and ...
patbarron's user avatar
  • 1,306
7 votes
Accepted

Is the kilobyte used by time and ulimit commands either 1000 (SI) or 1024 (old school) bytes?

It is kibibytes (1024), those are raw interfaces to the getrusage()/ setrlimit() APIs. Those documentations are inaccurate (or old-school as you say). Also note that the resource limits/accountings ...
Stéphane Chazelas's user avatar
6 votes

How to cause "Argument list too long" error?

Instead of listing all the files on the system, which takes forever and doesn't work on sparse systems, the command /bin/echo {1..200000} is a much faster (163ms) way to generate the error. For me ...
cat's user avatar
  • 3,538

Only top scored, non community-wiki answers of a minimum length are eligible