System Limit for Number of File Watchers Reached
On BSD systems with a default of 256 open file descriptors, Qt’s QFileSystemWatcher can be prevented from adding paths; on Linux, “System limit for number of file watchers reached” usually means your process has exhausted an inotify watcher or instance quota, not that the disk is full. The correct fix depends on whether the failing resource is an inotify watch, an inotify instance, or an ordinary open file descriptor. Start by identifying the error code, then reduce unnecessary watched paths before increasing a system limit.
Use this table to match the symptom to the resource that needs attention.
| Symptom | Likely Limit Reached | First Fix |
|---|---|---|
| A Linux watcher fails with ENOSPC while adding a watch or reports “System limit for number of file watchers reached” | inotify watches or inotify instances | Reduce watched paths and inspect the Linux inotify limits |
A process reports EMFILE or “Too many open files” |
Open file descriptors | Check the process limit and its systemd or PAM configuration |
QFileSystemWatcher cannot add paths on BSD |
Open file descriptors; the common default is 256 | Check the operating system’s open-file-descriptor limit |
| A large file cannot be copied to a drive | Destination file system limit, not a watcher limit | Check whether the destination is FAT32 |
| File creation slows or fails on IBM Storage Scale | Inode availability or configured file-count ceiling | Inspect the file system’s inode configuration |
What the File Watcher Limit Error Means
A file watcher asks the operating system to notify an application when files or directories change. Development servers, IDEs, test runners, container bind mounts, synchronization tools, and build systems commonly use them.
When a Linux watcher error involves inotify, inspect its limits separately from open-file limits. The kernel has separate limits for:
- Watches: individual file or directory registrations.
- Instances: inotify handles created by processes.
- Queued events: change notifications waiting to be read.
- Open file descriptors: handles used for files, sockets, pipes, and some watcher implementations.
The wording of the error matters:
ENOSPCwhile a watcher starts usually means an inotify resource is exhausted. In this context, it does not mean the storage volume is out of space.EMFILEor “Too many open files” means the process has reached its file-descriptor limit.- A watcher that starts successfully but misses changes may have an event-delivery, mount, permission, or application configuration problem rather than a watcher-count limit.
Increasing an open-file limit does not increase Linux inotify watch slots. Treat those as different limits until the error and diagnostics show otherwise.
A large monorepo can trigger the problem, but so can several tools watching the same tree under the same user account. For example, an editor, dev server, test runner, indexer, and containerized process may all register overlapping watches.
How to Fix the File Watcher Limit Error
Identifying the exhausted resource, reducing unnecessary watches, and raising only the relevant Linux inotify limit resolves the error.
Step 1: Identify the Exhausted Resource
- Capture the complete error from the application log or terminal. Look specifically for
ENOSPC,EMFILE,ENFILE, or a library-specific message such as “System limit for number of file watchers reached.” - On Linux, read the current inotify ceilings:
cat /proc/sys/fs/inotify/max_user_watches
cat /proc/sys/fs/inotify/max_user_instances
cat /proc/sys/fs/inotify/max_queued_events
- Check open-file limits separately from the inotify ceilings: For a program launched from your current shell, run:
cat /proc/$$/limits
For a service or another process, inspect /proc/<PID>/limits after replacing <PID> with that process’s numeric ID.
- Classify the result by the failure pattern: a failure after scanning a large workspace usually points to max_user_watches; one after repeatedly creating watcher clients, even for a small directory, can point to max_user_instances; and EMFILE points to the process’s open-file limit instead.
Do not change several limits at once. If you do, you will not know which resource was actually exhausted.
Step 2: Reduce the Number of Paths Being Watched
Before raising a system-wide quota, remove registrations that do not need live updates.
- Configure the affected tool to ignore generated and disposable directories. Common candidates include dependency caches, build output, coverage reports, logs, downloaded artifacts, and temporary directories.
- Keep source directories and configuration files watched if your workflow depends on live reload or incremental builds. Excluding active source files can hide the error while breaking reload behavior.
- Stop duplicate development processes. A stale dev server, second editor window, background test runner, or duplicate container can continue holding watches after you think it is no longer needed.
- Avoid watching an entire home directory, mounted drive, or workspace parent when the application only needs one project directory.
- Use polling only when the watcher is running on a file system where native notifications are unreliable, such as some remote, synchronized, or virtualized mounts. Polling can avoid an inotify-watch limit, but it increases CPU and disk activity.
Closing watcher-heavy programs that are no longer needed can free the inotify resources those programs hold.
Step 3: Raise the Relevant Linux Inotify Limit
If the error is ENOSPC and your application genuinely needs to watch more paths, increase the applicable inotify setting.
- Decide which setting needs adjustment: – Use
fs.inotify.max_user_watcheswhen the application needs to register more files or directories. – Usefs.inotify.max_user_instancesonly when it is creating too many separate inotify handles. - Choose a new limit based on the number of paths your tool registers, with room for the other development tools that run under the same user. There is no one safe universal value: a small project and a repository containing generated dependency trees can require very different limits.
- Create a persistent sysctl configuration file:
sudoedit /etc/sysctl.d/99-file-watchers.conf
- To persist the watch-limit setting you selected, add this line:
fs.inotify.max_user_watches = CHOSEN_WATCH_LIMIT
If the instance limit is the actual problem, use this line instead:
fs.inotify.max_user_instances = CHOSEN_INSTANCE_LIMIT
- Load the persistent sysctl configuration with:
sudo sysctl --system
- Verify the active setting by rereading the relevant file under /proc/sys/fs/inotify/, then restart the failing application so it creates a fresh watcher.
If a container cannot change the sysctl, follow that environment’s documented procedure for configuring the setting. A container-level change is not useful when the runtime blocks it.
Step 4: Raise the Service File-Descriptor Limit When EMFILE Is the Error
Use this step only when the process reports EMFILE, “Too many open files,” or a low Max open files value in /proc/<PID>/limits. It is not the normal fix for an inotify watch quota.
For example, to give the Amazon SSM Agent its own systemd limit, create a service override:
sudo mkdir -p /etc/systemd/system/amazon-ssm-agent.service.d
sudoedit /etc/systemd/system/amazon-ssm-agent.service.d/filelimit.conf
Add this configuration:
[Service]
LimitNOFILE=2048:8192
Here, 2048 is the soft limit and 8192 is the hard limit for the amazon-ssm-agent service. Confirm this exact setting in /etc/systemd/system/amazon-ssm-agent.service.d/filelimit.conf.
Reload systemd and restart the service:
sudo systemctl daemon-reload
sudo systemctl restart amazon-ssm-agent
Then inspect the running agent’s process limits in /proc/<PID>/limits. If the application error was EMFILE, restart its watcher or worker after the new limit is active.
BSD Qt, Systemd, and PAM Limit Cases
Qt File Watchers on BSD
On BSD systems, Qt’s QFileSystemWatcher can consume an open file descriptor for watched paths. On some BSD systems, the default descriptor limit is 256, so an application can fail to add paths even when the disk has ample space.
Check the operating system’s open-file-descriptor limit for the shell, service, or application that starts Qt. Raise that process limit using the operating system’s normal service or login-session mechanism; changing Linux inotify settings will not affect BSD Qt watcher behavior.
Setting a Default Limit for Systemd Services
A per-service override is safer than changing every service. If many services under systemd genuinely need a higher default open-file limit, create the default configuration directory:
sudo mkdir -p /etc/systemd/system.conf.d
Open the configuration file:
sudoedit /etc/systemd/system.conf.d/filelimit.conf
Add:
[Manager]
DefaultLimitNOFILE=3072:12288
This sets the default soft limit to 3072 and hard limit to 12288 for services started under systemd. Confirm the intended values in /etc/systemd/system.conf.d/filelimit.conf.
Reload the systemd manager:
sudo systemctl daemon-reexec
Restart the affected services afterward. Existing processes keep the limits they had when they were started, so a manager reload alone does not repair an already-running watcher.
PAM Login Limits Do Not Configure Systemd Daemons
For interactive login sessions that pass through PAM, /etc/security/limits.conf can set open-file limits. These entries set both the soft and hard nofile limit to 65534:
* soft nofile 65534
* hard nofile 65534
Those settings apply to PAM-managed login sessions, not automatically to systemd daemons. Log out and back in after changing the file, then verify the affected process through /proc/<PID>/limits.
This distinction explains a common CentOS 7 behavior: a command run without sudo can have a soft descriptor limit of 1024 and a hard limit of 4096, while a command run through sudo can receive PAM-applied limits of 65534 for both. Check the actual process rather than assuming the shell, SSH session, and systemd service share the same limits.
File Count Limits Are Not File Watcher Limits
A watcher limit controls how many paths an application can monitor. It does not determine how many files a file system can store.
On IBM Storage Scale, the inode-limit file-system creation setting specifies the maximum number of files that can exist in the file system. The exact configured value is specific to that file system; inspect its creation configuration and the current configuration with the mmlsfs utility. IBM Storage Scale documentation also gives an approximate planning formula:
Maximum number of files = total system pool space / (inode size + subblock size)
That estimate depends on the system pool space, inode size, and subblock size selected when the file system was created. A file system using only the system storage pool has to hold both data and metadata there, which lowers the practical number of files it can hold.
For Storage Scale file systems that support parallel file creation, file-system access can slow down when free inodes fall below 5% of the total inode count. That is an inode-capacity planning problem, not an inotify watcher error.
A file-copy failure can also be unrelated to watchers. FAT32 has a maximum individual file size of 4 GB, so copying a larger file to a FAT32 drive will fail even if the machine has no watcher or descriptor pressure.
Confirm the Fix and Prevent It From Returning
After making one targeted change, verify both the limit and the application behavior.
- Recheck the inotify value under
/proc/sys/fs/inotify/if you changed an inotify setting. - Check
/proc/<PID>/limitsif you changed a descriptor limit for a user session or service. - Restart the watcher rather than assuming a running process will re-read system limits.
- Create and remove a harmless temporary file in a watched source directory, then confirm the application detects both changes.
- Restart the machine or service if you need to confirm that a persistent sysctl, systemd override, or PAM configuration survives a new session.
- Keep watcher exclusions in project configuration so teammates and CI environments do not watch generated directories by default.
If the error returns, capture the exact error code and the affected process’s limits before making another change. That evidence will tell you whether the remaining problem is still an inotify quota, an open-file limit, or a file-system constraint.
Frequently Asked Questions
Does FAT32 Have a Maximum File Size?
Yes. FAT32 has a maximum individual file size of 4 GB. That restriction affects copying or creating a large file on a FAT32 volume; it does not cause “System limit for number of file watchers reached.”
Is There a Limit on the Number of Files in a Folder?
There is no single universal limit for every operating system and file system. The practical limit depends on the file system’s directory design, available inodes or metadata space, and application behavior; a folder with many entries can also become slow for tools that scan or watch it.
What Do File System Limitations Include?
File-system limitations include total storage capacity, maximum file size, maximum file count, inode or metadata capacity, supported filename and path rules, permissions, and quotas. A file watcher limit is different: it is an operating-system resource limit for monitoring changes, not a limit on storing files.
Why Does a Command Have Different Limits With and Without sudo?
PAM session handling can apply different resource limits to commands started through sudo than to commands started directly. In the stated CentOS 7 case, a non-sudo command had a soft descriptor limit of 1024 and a hard limit of 4096, while PAM-applied settings could set both limits to 65534. Inspect /proc/<PID>/limits for the process that actually fails.
Will Raising the Open-File Limit Fix Every Watcher Error?
No. Raising an open-file limit fixes descriptor exhaustion such as EMFILE, but it does not raise Linux’s inotify watch or instance quotas. For an ENOSPC watcher error, inspect the inotify limits and reduce unnecessary watched paths before increasing the relevant kernel setting.
