> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Fix "Too many open files" (ulimit) on Linux

> Fix "Too many open files" on Linux: check /proc/PID/limits, raise LimitNOFILE for systemd services or nofile in limits.conf, and look for descriptor leaks.

"Too many open files" means a program reached its limit of file descriptors: open files, network connections and pipes all count. On most systemd distributions, services start with a soft limit of `1024`. Check the real limit with `grep 'open files' /proc/<PID>/limits`, then raise it for a service with `LimitNOFILE=65535` in a systemd override, or for login sessions with `nofile` in `/etc/security/limits.conf`.

```text theme={null}
OSError: [Errno 24] Too many open files
accept4() failed (24: Too many open files)
```

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Intermediate | 10 to 20 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux and Rocky Linux 9 / 10 | Root or sudo access |

## Before you start

* A **file descriptor** is a number a program uses for each open file or connection. Busy web servers, databases and game servers with many players need thousands.
* Each process has a **soft** limit (what applies now) and a **hard** limit (the most the soft limit may be raised to).
* Commands use `sudo`. As root, leave it out.

## Step 1: Check the limit and the usage

Find the process ID (PID), for example of Nginx:

```bash theme={null}
pgrep -o nginx
```

Then show its limit and how many descriptors it has open (replace `812` with your PID):

```bash theme={null}
grep 'open files' /proc/812/limits
sudo ls /proc/812/fd | wc -l
```

```text theme={null}
Max open files            1024                 524288               files
```

The first number is the soft limit, the second the hard limit. If the count is close to the soft limit, raise it (Causes 1 and 2). If the count keeps climbing however high the limit is, see Cause 3.

## Cause 1: A systemd service has a low limit

Services started by systemd ignore `ulimit` and `limits.conf`. They take the limit from their unit, which defaults to `1024` soft and `524288` hard.

**Fix:** open an override for the service:

```bash theme={null}
sudo systemctl edit nginx
```

Add:

```ini theme={null}
[Service]
LimitNOFILE=65535
```

Save, then restart:

```bash theme={null}
sudo systemctl restart nginx
```

For **Nginx**, also let the workers use it: in `/etc/nginx/nginx.conf`, at the top level, add `worker_rlimit_nofile 65535;`, check with `sudo nginx -t` and reload. For **MariaDB/MySQL**, raise `LimitNOFILE` the same way on the `mariadb` or `mysql` unit.

## Cause 2: A program started from your shell or a login has a low limit

Programs you start by hand, in tmux or screen, or from cron get the limit of your login session.

**Check:**

```bash theme={null}
ulimit -Sn
ulimit -Hn
```

**Fix for the current shell** (up to the hard limit):

```bash theme={null}
ulimit -n 65535
```

**Fix permanently** for a user: add these lines to `/etc/security/limits.conf` (or a new file in `/etc/security/limits.d/`), then log out and back in:

```text theme={null}
alex  soft  nofile  65535
alex  hard  nofile  65535
```

**Fix a process that is already running** without a restart:

```bash theme={null}
sudo prlimit --pid 812 --nofile=65535:65535
```

This lasts until the process stops. Make the permanent change too.

## Cause 3: A program leaks file descriptors

If the count from Step 1 grows all day and never drops, the program opens files or connections and doesn't close them. A higher limit only delays the error.

**Check** what it keeps open:

```bash theme={null}
sudo ls -l /proc/812/fd | awk '{print $NF}' | sort | uniq -c | sort -rn | head
```

Many `socket:[...]` entries point to unclosed connections; the same file name many times points to a file opened in a loop.

**Fix:** update the program or report the bug to its developer. Until then, restart it on a schedule.

## Cause 4: inotify limits (file watchers)

Tools that watch files (`tail -f`, Node.js dev servers, sync tools, some game panels) use inotify, which has its own per-user limits. They report the same error, for example `tail: inotify cannot be used, reverting to polling: Too many open files`.

**Check:**

```bash theme={null}
sysctl fs.inotify.max_user_instances fs.inotify.max_user_watches
```

**Fix:** raise them permanently:

```bash theme={null}
echo -e 'fs.inotify.max_user_instances = 1024\nfs.inotify.max_user_watches = 524288' | sudo tee /etc/sysctl.d/60-inotify.conf
sudo sysctl --system
```

## How to check it worked

Repeat Step 1 after the restart:

```bash theme={null}
grep 'open files' /proc/$(pgrep -o nginx)/limits
```

```text theme={null}
Max open files            65535                65535                files
```

## Frequently asked questions

### I set limits.conf but my service still has 1024. Why?

`limits.conf` only applies to login sessions through PAM. systemd services need `LimitNOFILE` in their unit (Cause 1).

### What value should I use?

`65535` is plenty for most web servers, databases and game servers. Some vendors recommend more; follow their documentation for that program.

### What does "Too many open files in system" mean?

That is the system-wide limit (`fs.file-max`), not a per-process one. It is rare on current kernels; check with `cat /proc/sys/fs/file-nr`, and look for a leak (Cause 3) before raising it.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Manage services with systemctl](https://help.freakhosting.com/portals/other/how-to-manage-services-with-systemctl.md)
>
> Overrides, restarts and status.

> [card] [Kernel settings with sysctl](https://help.freakhosting.com/portals/other/how-to-secure-shared-memory-and-kernel-settings-with-sysctl.md)
>
> Make kernel settings permanent.

> [card] [Tune Linux for game servers](https://help.freakhosting.com/portals/other/how-to-tune-linux-for-game-servers.md)
>
> Limits and settings for busy servers.

> [card] [High load on a Linux server](https://help.freakhosting.com/portals/other/how-to-fix-high-load-on-a-linux-server.md)
>
> Find what slows the server down.

***

> [!NOTE]
>
> **Checked against the official systemd [systemd.exec](https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html) and [systemd-system.conf](https://www.freedesktop.org/software/systemd/man/latest/systemd-system.conf.html) manuals, the [limits.conf](https://man7.org/linux/man-pages/man5/limits.conf.5.html) and [prlimit](https://man7.org/linux/man-pages/man1/prlimit.1.html) manuals and the [nginx core module documentation](https://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile)** on 4 November 2026; the error (Python and Bash), `/proc/PID/limits`, `ulimit`, `prlimit` and the inotify `sysctl` values were tested on Ubuntu 24.04 LTS. The systemd override was not tested, because systemd doesn't run in our test container.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.