Skip to the content ForoHackers
Log inJoin

Shy question: what does ulimit -n actually limit?

Linux
#1011 · anonymous · · Report

Embarrassed to ask because I have seen the error "Too many open files" for years and just copy the fix from somewhere.

I run ulimit -n and get 1024. What is the thing it limits? Is it files? Network connections? Per user or per process? And why does the fix always mention a different file depending on whether it is a service?

#1426 · anonymous · · Report

It limits file descriptors per process. A descriptor is the number the kernel gives your process for anything it has open: regular files, sockets (so, network connections), pipes, and so on. Each process gets a soft limit (what you hit, 1024 here) and a hard limit (the ceiling an unprivileged process can raise its soft limit to).

Not per user: per process, and inherited by its children.

#1427 · anonymous · · Report

Why different files: a shell you log into gets its limits from PAM (/etc/security/limits.conf and limits.d). A service started by systemd ignores that and takes LimitNOFILE= from its unit file (use a drop-in override, not an edit). So the right fix depends on how the process was started, and cat /proc/PID/limits tells you which limit it really has.

#1428 · anonymous · · Report

And before raising the number, ask whether the process is leaking descriptors. ls /proc/PID/fd | wc -l over time: if it only goes up, you do not need a bigger limit, you need a close().

Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply