📜  linux watchers limit - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:32:40.748000             🧑  作者: Mango

Linux watchers limit - Shell/Bash

In Linux, inotify is a powerful file watching mechanism that allows you to monitor directory trees for changes. However, there are default limitations to the number of watches that can be set.

What is the watchers limit?

The watchers limit is the maximum number of directories that can be monitored by inotify. This limit is defined by the kernel, and in some cases, it can cause problems if not adjusted correctly.

The default value for the watchers limit is usually 8192. However, this value can be too low if you're trying to monitor a large number of files, which can cause inotify to return error messages.

How to check the current limit value?

You can check the current value of inotify watchers limit by running the following command:

cat /proc/sys/fs/inotify/max_user_watches

This will output the current value of inotify watchers limit.

How to increase the watchers limit?

To increase the watchers limit, you need to edit the /etc/sysctl.conf file and add the following line:

fs.inotify.max_user_watches= <new value>

Replace <new value> with the new limit you want to set. For example, to set the limit to 100000, you would use:

fs.inotify.max_user_watches=100000

Save the file and exit.

To apply the changes immediately, run the following command:

sudo sysctl -p

This will reload the sysctl configuration file and apply the new value for inotify watchers limit.

Conclusion

The default value of inotify watchers limit can cause issues if you're trying to monitor a large number of files. By increasing the limit, you can avoid errors and ensure that your file monitoring system works as expected in Linux.