Saltar al contenido ForoHackers

Shy question: what does ulimit -n actually limit?

Linux
#1011 · anónimo · · Denunciar

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 · anónimo · · Denunciar

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 · anónimo · · Denunciar

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 · anónimo · · Denunciar

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().

Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder