brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: prlimit changes the limits of a Linux process that is already running

Linux
~/tips/tip-linux-prlimit-pid-running-process

prlimit --pid 1234 --nofile

Raise the open files limit of a running service without restarting it.

A service hits Too many open files in the middle of the day. The real fix belongs in its config, but restarting it right now would drop every connection. prlimit can change its limit while it runs.

prlimit --pid 1234 --nofile

This shows the current soft and hard limit for open files of process 1234. To raise both:

prlimit --pid 1234 --nofile=65536:65536

The number before the colon is the soft limit, the one the process runs into. The number after it is the hard limit, the ceiling the soft limit may be raised to. The change takes effect immediately, and the next file the process opens counts against the new limit.

It works for the other limits too, such as --core for core dump size or --nproc for the number of processes. Leave out all options and prlimit --pid 1234 prints a table of every limit, which is a friendlier view than /proc/1234/limits.

You can also start a command with different limits, like prlimit --nofile=4096 ./server.

Raising a hard limit, or changing the limits of a process owned by someone else, needs root. A change like this lasts only for the life of that process; after a restart, the service gets whatever its config gives it again. So I’d treat it as first aid and then set the value permanently, for a systemd service with LimitNOFILE= in an override. Some programs also read their limit once at startup and size internal tables from it, so they may not use the extra room until they restart anyway.

Further reading: prlimit(1) manual page, getrlimit(2) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link