]>
Commit | Line | Data |
---|---|---|
4d2b74dd | 1 | '\" t |
415f63be | 2 | .\" Copyright (C) 2006, 2014 Michael Kerrisk <mtk.manpages@gmail.com> |
4d2b74dd | 3 | .\" |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
4d2b74dd MK |
5 | .\" Permission is granted to make and distribute verbatim copies of this |
6 | .\" manual provided the copyright notice and this permission notice are | |
7 | .\" preserved on all copies. | |
8 | .\" | |
9 | .\" Permission is granted to copy and distribute modified versions of this | |
10 | .\" manual under the conditions for verbatim copying, provided that the | |
11 | .\" entire resulting derived work is distributed under the terms of a | |
12 | .\" permission notice identical to this one. | |
c13182ef | 13 | .\" |
4d2b74dd MK |
14 | .\" Since the Linux kernel and libraries are constantly changing, this |
15 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
16 | .\" responsibility for errors or omissions, or for damages resulting from | |
10d76543 MK |
17 | .\" the use of the information contained herein. The author(s) may not |
18 | .\" have taken the same level of care in the production of this manual, | |
19 | .\" which is licensed free of charge, as they might when working | |
20 | .\" professionally. | |
c13182ef | 21 | .\" |
4d2b74dd MK |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
4d2b74dd | 25 | .\" |
7b5151b7 | 26 | .TH INOTIFY 7 2014-03-28 "Linux" "Linux Programmer's Manual" |
4d2b74dd | 27 | .SH NAME |
9ee4a2b6 | 28 | inotify \- monitoring filesystem events |
4d2b74dd MK |
29 | .SH DESCRIPTION |
30 | The | |
c13182ef | 31 | .I inotify |
9ee4a2b6 | 32 | API provides a mechanism for monitoring filesystem events. |
4d2b74dd MK |
33 | Inotify can be used to monitor individual files, |
34 | or to monitor directories. | |
35 | When a directory is monitored, inotify will return events | |
36 | for the directory itself, and for files inside the directory. | |
37 | ||
c13182ef | 38 | The following system calls are used with this API: |
43bb5faf | 39 | .BR inotify_init (2) |
c5571b61 | 40 | (or |
43bb5faf | 41 | .BR inotify_init1 (2)), |
63f6a20a MK |
42 | .BR inotify_add_watch (2), |
43 | .BR inotify_rm_watch (2), | |
44 | .BR read (2), | |
c13182ef | 45 | and |
63f6a20a | 46 | .BR close (2). |
4d2b74dd MK |
47 | |
48 | .BR inotify_init (2) | |
c13182ef | 49 | creates an inotify instance and returns a file descriptor |
a2cc46ca | 50 | referring to the inotify instance. |
43bb5faf MK |
51 | The more recent |
52 | .BR inotify_init1 (2) | |
53 | is like | |
54 | .BR inotify_init (2), | |
55 | but provides some extra functionality. | |
4d2b74dd MK |
56 | |
57 | .BR inotify_add_watch (2) | |
a2cc46ca | 58 | manipulates the "watch list" associated with an inotify instance. |
3a065ac0 | 59 | Each item ("watch") in the watch list specifies the pathname of |
c13182ef | 60 | a file or directory, |
4d2b74dd MK |
61 | along with some set of events that the kernel should monitor for the |
62 | file referred to by that pathname. | |
63f6a20a | 63 | .BR inotify_add_watch (2) |
4d2b74dd MK |
64 | either creates a new watch item, or modifies an existing watch. |
65 | Each watch has a unique "watch descriptor", an integer | |
66 | returned by | |
63f6a20a | 67 | .BR inotify_add_watch (2) |
4d2b74dd MK |
68 | when the watch is created. |
69 | ||
70 | .BR inotify_rm_watch (2) | |
71 | removes an item from an inotify watch list. | |
72 | ||
c13182ef | 73 | When all file descriptors referring to an inotify |
a2cc46ca | 74 | instance have been closed, |
c13182ef | 75 | the underlying object and its resources are |
3b777aff | 76 | freed for reuse by the kernel; |
4d2b74dd MK |
77 | all associated watches are automatically freed. |
78 | ||
79 | To determine what events have occurred, an application | |
80 | .BR read (2)s | |
81 | from the inotify file descriptor. | |
c13182ef | 82 | If no events have so far occurred, then, |
11da88fb | 83 | assuming a blocking file descriptor, |
63f6a20a | 84 | .BR read (2) |
01538d0d MK |
85 | will block until at least one event occurs |
86 | (unless interrupted by a signal, | |
87 | in which case the call fails with the error | |
88 | .BR EINTR ; | |
89 | see | |
90 | .BR signal (7)). | |
4d2b74dd MK |
91 | |
92 | Each successful | |
63f6a20a | 93 | .BR read (2) |
4d2b74dd | 94 | returns a buffer containing one or more of the following structures: |
a08ea57c | 95 | .in +4n |
4d2b74dd MK |
96 | .nf |
97 | ||
98 | struct inotify_event { | |
99 | int wd; /* Watch descriptor */ | |
24bbe02c MK |
100 | .\" FIXME . The type of the 'wd' field should probably be "int32_t". |
101 | .\" I submitted a patch to fix this. See the LKML thread | |
102 | .\" "[patch] Fix type errors in inotify interfaces", 18 Nov 2008 | |
6e6231c1 | 103 | .\" Glibc bug filed: http://sources.redhat.com/bugzilla/show_bug.cgi?id=7040 |
4d2b74dd | 104 | uint32_t mask; /* Mask of events */ |
c13182ef | 105 | uint32_t cookie; /* Unique cookie associating related |
4d2b74dd | 106 | events (for rename(2)) */ |
84c517a4 | 107 | uint32_t len; /* Size of \fIname\fP field */ |
4d2b74dd MK |
108 | char name[]; /* Optional null-terminated name */ |
109 | }; | |
110 | .fi | |
a08ea57c | 111 | .in |
4d2b74dd MK |
112 | |
113 | .I wd | |
114 | identifies the watch for which this event occurs. | |
c13182ef | 115 | It is one of the watch descriptors returned by a previous call to |
63f6a20a | 116 | .BR inotify_add_watch (2). |
4d2b74dd MK |
117 | |
118 | .I mask | |
119 | contains bits that describe the event that occurred (see below). | |
120 | ||
121 | .I cookie | |
122 | is a unique integer that connects related events. | |
33a0ccb2 | 123 | Currently this is used only for rename events, and |
4d2b74dd | 124 | allows the resulting pair of |
bc636d8a | 125 | .B IN_MOVED_FROM |
c13182ef | 126 | and |
bc636d8a | 127 | .B IN_MOVED_TO |
4d2b74dd | 128 | events to be connected by the application. |
591b7a5f MK |
129 | For all other event types, |
130 | .I cookie | |
131 | is set to 0. | |
4d2b74dd | 132 | |
c13182ef | 133 | The |
4d2b74dd | 134 | .I name |
33a0ccb2 | 135 | field is present only when an event is returned |
c13182ef | 136 | for a file inside a watched directory; |
4d2b74dd | 137 | it identifies the file pathname relative to the watched directory. |
c13182ef | 138 | This pathname is null-terminated, |
1aff5804 | 139 | and may include further null bytes (\(aq\\0\(aq) to align subsequent reads to a |
4d2b74dd MK |
140 | suitable address boundary. |
141 | ||
142 | The | |
143 | .I len | |
c13182ef | 144 | field counts all of the bytes in |
4d2b74dd | 145 | .IR name , |
c13182ef | 146 | including the null bytes; |
4d2b74dd MK |
147 | the length of each |
148 | .I inotify_event | |
149 | structure is thus | |
655684a9 | 150 | .IR "sizeof(struct inotify_event)+len" . |
c7e3ee6f | 151 | |
988db661 | 152 | The behavior when the buffer given to |
c7e3ee6f | 153 | .BR read (2) |
988db661 | 154 | is too small to return information about the next event depends |
c7e3ee6f MK |
155 | on the kernel version: in kernels before 2.6.21, |
156 | .BR read (2) | |
157 | returns 0; since kernel 2.6.21, | |
158 | .BR read (2) | |
159 | fails with the error | |
160 | .BR EINVAL . | |
4ba272b3 MK |
161 | Specifying a buffer of size |
162 | ||
163 | sizeof(struct inotify_event) + NAME_MAX + 1 | |
164 | ||
165 | will be sufficient to read at least one event. | |
4d2b74dd | 166 | .SS inotify events |
c13182ef | 167 | The |
4d2b74dd MK |
168 | .BR inotify_add_watch (2) |
169 | .I mask | |
c13182ef | 170 | argument and the |
4d2b74dd MK |
171 | .I mask |
172 | field of the | |
173 | .I inotify_event | |
174 | structure returned when | |
175 | .BR read (2)ing | |
176 | an inotify file descriptor are both bit masks identifying | |
177 | inotify events. | |
178 | The following bits can be specified in | |
179 | .I mask | |
180 | when calling | |
63f6a20a | 181 | .BR inotify_add_watch (2) |
c13182ef | 182 | and may be returned in the |
4d2b74dd MK |
183 | .I mask |
184 | field returned by | |
63f6a20a | 185 | .BR read (2): |
64aa9bcb | 186 | .RS 4 |
c577b95c | 187 | .TP |
f23fc716 | 188 | .BR IN_ACCESS " (*)" |
70f70c9d MK |
189 | File was accessed (e.g., |
190 | .BR read (2), | |
f23fc716 | 191 | .BR execve (2)). |
3f174f7d | 192 | .TP |
f23fc716 | 193 | .BR IN_ATTRIB " (*)" |
b0e1ac43 MK |
194 | Metadata changed\(emfor example, permissions (e.g., |
195 | .BR chmod (2)), | |
196 | timestamps (e.g., | |
197 | .BR utimensat (2)), | |
198 | extended attributes | |
199 | .RB ( setxattr (2)), | |
200 | link count (since Linux 2.6.25; e.g., | |
201 | for the target of | |
202 | .BR link (2) | |
203 | and for | |
204 | .BR unlink (2)), | |
205 | and user/group ID (e.g., | |
206 | .BR chown (2)). | |
3f174f7d | 207 | .TP |
f23fc716 MK |
208 | .BR IN_CLOSE_WRITE " (*)" |
209 | File opened for writing was closed. | |
3f174f7d | 210 | .TP |
f23fc716 MK |
211 | .BR IN_CLOSE_NOWRITE " (*)" |
212 | File not opened for writing was closed. | |
3f174f7d | 213 | .TP |
f23fc716 | 214 | .BR IN_CREATE " (*)" |
7a64793b MK |
215 | File/directory created in watched directory (e.g., |
216 | .BR open (2) | |
217 | .BR O_CREAT , | |
218 | .BR mkdir (2), | |
219 | .BR link (2), | |
220 | .BR bind (2) | |
221 | on a UNIX domain socket). | |
3f174f7d | 222 | .TP |
f23fc716 MK |
223 | .BR IN_DELETE " (*)" |
224 | File/directory deleted from watched directory. | |
3f174f7d MK |
225 | .TP |
226 | .B IN_DELETE_SELF | |
227 | Watched file/directory was itself deleted. | |
4a1e4cca MK |
228 | (This event also occurs if an object is moved to another filesystem, |
229 | since | |
230 | .BR mv (1) | |
231 | in effect copies the file to the other filesystem and | |
49b07b8f | 232 | then deletes it from the original filesystem.) |
39f43968 MK |
233 | In addition, an |
234 | .B IN_IGNORED | |
235 | event will subsequently be generated for the watch descriptor. | |
3f174f7d | 236 | .TP |
f23fc716 | 237 | .BR IN_MODIFY " (*)" |
f54a1255 MK |
238 | File was modified (e.g., |
239 | .BR write (2), | |
240 | .BR truncate (2)). | |
3f174f7d MK |
241 | .TP |
242 | .B IN_MOVE_SELF | |
243 | Watched file/directory was itself moved. | |
244 | .TP | |
f23fc716 | 245 | .BR IN_MOVED_FROM " (*)" |
107375cf | 246 | Generated for the directory containing the old filename |
f23fc716 | 247 | when a file is renamed. |
3f174f7d | 248 | .TP |
f23fc716 | 249 | .BR IN_MOVED_TO " (*)" |
107375cf | 250 | Generated for the directory containing the new filename |
f23fc716 | 251 | when a file is renamed. |
3f174f7d | 252 | .TP |
f23fc716 MK |
253 | .BR IN_OPEN " (*)" |
254 | File was opened. | |
64aa9bcb | 255 | .RE |
4d2b74dd | 256 | .PP |
c13182ef MK |
257 | When monitoring a directory, |
258 | the events marked with an asterisk (*) above can occur for | |
4d2b74dd MK |
259 | files in the directory, in which case the |
260 | .I name | |
261 | field in the returned | |
262 | .I inotify_event | |
263 | structure identifies the name of the file within the directory. | |
264 | .PP | |
265 | The | |
266 | .B IN_ALL_EVENTS | |
267 | macro is defined as a bit mask of all of the above events. | |
268 | This macro can be used as the | |
269 | .I mask | |
270 | argument when calling | |
63f6a20a | 271 | .BR inotify_add_watch (2). |
4d2b74dd | 272 | |
dede00fe | 273 | Two additional convenience macros are defined: |
64aa9bcb | 274 | .RS 4 |
dede00fe MK |
275 | .TP |
276 | .BR IN_MOVE | |
277 | Equates to | |
278 | .BR "IN_MOVED_FROM | IN_MOVED_TO" . | |
279 | .TP | |
280 | .BR IN_CLOSE | |
281 | Equates to | |
282 | .BR "IN_CLOSE_WRITE | IN_CLOSE_NOWRITE" . | |
64aa9bcb | 283 | .RE |
4d2b74dd | 284 | .PP |
c13182ef | 285 | The following further bits can be specified in |
4d2b74dd MK |
286 | .I mask |
287 | when calling | |
63f6a20a | 288 | .BR inotify_add_watch (2): |
64aa9bcb | 289 | .RS 4 |
c577b95c | 290 | .TP |
31daf529 | 291 | .BR IN_DONT_FOLLOW " (since Linux 2.6.15)" |
aeb9b6a6 MK |
292 | Don't dereference |
293 | .I pathname | |
294 | if it is a symbolic link. | |
dda869a4 | 295 | .TP |
0ff2cc88 | 296 | .BR IN_EXCL_UNLINK " (since Linux 2.6.36)" |
b3ad7609 MK |
297 | .\" commit 8c1934c8d70b22ca8333b216aec6c7d09fdbd6a6 |
298 | By default, when watching events on the children of a directory, | |
299 | events are generated for children even after they have been unlinked | |
300 | from the directory. | |
301 | This can result in large numbers of uninteresting events for | |
302 | some applications (e.g., if watching | |
303 | .IR /tmp , | |
304 | in which many applications create temporary files whose | |
305 | names are immediately unlinked). | |
306 | Specifying | |
307 | .B IN_EXCL_UNLINK | |
308 | changes the default behavior, | |
309 | so that events are not generated for children after | |
310 | they have been unlinked from the watched directory. | |
311 | .TP | |
dda869a4 MK |
312 | .B IN_MASK_ADD |
313 | Add (OR) events to watch mask for this pathname if | |
314 | it already exists (instead of replacing mask). | |
315 | .TP | |
316 | .B IN_ONESHOT | |
aeb9b6a6 MK |
317 | Monitor |
318 | .I pathname | |
319 | for one event, then remove from | |
dda869a4 MK |
320 | watch list. |
321 | .TP | |
31daf529 | 322 | .BR IN_ONLYDIR " (since Linux 2.6.15)" |
aeb9b6a6 MK |
323 | Only watch |
324 | .I pathname | |
325 | if it is a directory. | |
64aa9bcb | 326 | .RE |
4d2b74dd MK |
327 | .PP |
328 | The following bits may be set in the | |
329 | .I mask | |
330 | field returned by | |
63f6a20a | 331 | .BR read (2): |
64aa9bcb | 332 | .RS 4 |
c577b95c | 333 | .TP |
dda869a4 | 334 | .B IN_IGNORED |
aeb9b6a6 MK |
335 | Watch was removed explicitly |
336 | .RB ( inotify_rm_watch (2)) | |
9ee4a2b6 | 337 | or automatically (file was deleted, or filesystem was unmounted). |
7b5151b7 | 338 | See also BUGS. |
dda869a4 MK |
339 | .TP |
340 | .B IN_ISDIR | |
341 | Subject of this event is a directory. | |
342 | .TP | |
343 | .B IN_Q_OVERFLOW | |
aeb9b6a6 MK |
344 | Event queue overflowed |
345 | .RI ( wd | |
346 | is \-1 for this event). | |
dda869a4 MK |
347 | .TP |
348 | .B IN_UNMOUNT | |
9ee4a2b6 | 349 | Filesystem containing watched object was unmounted. |
b01c936e MK |
350 | In addition, an |
351 | .B IN_IGNORED | |
352 | event will subsequently be generated for the watch descriptor. | |
64aa9bcb | 353 | .RE |
415f63be MK |
354 | .SS Examples |
355 | Suppose an application is watching the directory | |
356 | .I dir | |
357 | and the file | |
358 | .IR dir/myfile | |
359 | for all events. | |
360 | The examples below show some events that will be generated | |
361 | for these two objects. | |
362 | .RS 4 | |
363 | .TP | |
364 | fd = open("dir/myfile", O_RDWR); | |
365 | Generates | |
366 | .B IN_OPEN | |
367 | events for both | |
368 | .I dir | |
369 | and | |
370 | .IR dir/myfile . | |
371 | .TP | |
372 | read(fd, buf, count); | |
373 | Generates | |
374 | .B IN_ACCESS | |
375 | events for both | |
376 | .I dir | |
377 | and | |
378 | .IR dir/myfile . | |
379 | .TP | |
380 | write(fd, buf, count); | |
381 | Generates | |
382 | .B IN_MODIFY | |
383 | events for both | |
384 | .I dir | |
385 | and | |
386 | .IR dir/myfile . | |
387 | .TP | |
388 | fchmod(fd, mode); | |
389 | Generates | |
390 | .B IN_ATTRIB | |
391 | events for both | |
392 | .I dir | |
393 | and | |
394 | .IR dir/myfile . | |
395 | .TP | |
396 | close(fd); | |
397 | Generates | |
398 | .B IN_CLOSE_WRITE | |
399 | events for both | |
400 | .I dir | |
401 | and | |
402 | .IR dir/myfile . | |
403 | .RE | |
404 | .PP | |
405 | Suppose an application is watching the directories | |
406 | .I dir1 | |
407 | and | |
408 | .IR dir , | |
409 | and the file | |
410 | .IR dir1/myfile . | |
411 | The following examples show some events that may be generated. | |
412 | .RS 4 | |
413 | .TP | |
414 | link("dir/myfile", "dir2/new"); | |
415 | Generates an | |
416 | .B IN_ATTRIB | |
417 | event for | |
418 | .IR myfile | |
419 | and an | |
420 | .B IN_CREATE | |
421 | event for | |
422 | .IR dir2 . | |
423 | .TP | |
424 | rename("dir1/myfile", "dir2/myfile"); | |
425 | Generates an | |
426 | .B IN_MOVED_FROM | |
427 | event for | |
428 | .IR dir1 , | |
429 | an | |
430 | .B IN_MOVED_TO | |
431 | event for | |
432 | .IR dir2 , | |
433 | and an | |
434 | .B IN_MOVE_SELF | |
435 | event for | |
436 | .IR myfile . | |
437 | The | |
438 | .B IN_MOVED_FROM | |
439 | and | |
440 | .B IN_MOVED_TO | |
441 | events will have the same | |
442 | .I cookie | |
443 | value. | |
444 | .RE | |
445 | .PP | |
446 | Suppose that | |
447 | .IR dir1/xx | |
448 | and | |
449 | .IR dir2/yy | |
450 | are (the only) links to the same file, and an application is watching | |
451 | .IR dir1 , | |
452 | .IR dir2 , | |
453 | .IR dir1/xx , | |
454 | and | |
455 | .IR dir2/yy . | |
456 | Executing the following calls in the order given below will generate | |
457 | the following events: | |
458 | .RS 4 | |
459 | .TP | |
460 | unlink("dir2/yy"); | |
461 | Generates | |
462 | .BR IN_ATTRIB | |
463 | event for | |
464 | .IR xx | |
465 | (because its link count changes) | |
466 | and an | |
467 | .B IN_DELETE | |
468 | event for | |
469 | .IR dir2 . | |
470 | .TP | |
471 | unlink("dir1/xx"); | |
472 | Generates | |
473 | .BR IN_ATTRIB , | |
474 | .BR IN_DELETE_SELF , | |
475 | and | |
476 | .BR IN_IGNORED | |
477 | events for | |
478 | .IR xx , | |
479 | and an | |
480 | .BR IN_DELETE | |
481 | for | |
482 | .IR dir1 . | |
483 | .RE | |
484 | .PP | |
485 | Suppose an application is watching the directory | |
486 | .IR dir | |
487 | and (the empty) directory | |
488 | .IR dir/subdir . | |
489 | The following examples show some events that may be generated. | |
490 | .RS 4 | |
491 | .TP | |
492 | mkdir("dir/new", mode); | |
493 | Generates an | |
494 | .B "IN_CREATE | IN_ISDIR" | |
495 | event for | |
496 | .IR dir . | |
497 | .TP | |
498 | rmdir("dir/sub"); | |
499 | Generates | |
500 | .B IN_DELETE_SELF | |
501 | and | |
502 | .B IN_IGNORED | |
503 | events for | |
504 | .IR subdir , | |
505 | and an | |
506 | .B "IN_DELETE | IN_ISDIR" | |
507 | event for | |
508 | .IR dir . | |
509 | .RE | |
4d2b74dd | 510 | .SS /proc interfaces |
c13182ef | 511 | The following interfaces can be used to limit the amount of |
4d2b74dd MK |
512 | kernel memory consumed by inotify: |
513 | .TP | |
0daa9e92 | 514 | .I /proc/sys/fs/inotify/max_queued_events |
4d2b74dd MK |
515 | The value in this file is used when an application calls |
516 | .BR inotify_init (2) | |
c13182ef | 517 | to set an upper limit on the number of events that can be |
4d2b74dd MK |
518 | queued to the corresponding inotify instance. |
519 | Events in excess of this limit are dropped, but an | |
520 | .B IN_Q_OVERFLOW | |
521 | event is always generated. | |
522 | .TP | |
0daa9e92 | 523 | .I /proc/sys/fs/inotify/max_user_instances |
c13182ef | 524 | This specifies an upper limit on the number of inotify instances |
4d2b74dd MK |
525 | that can be created per real user ID. |
526 | .TP | |
0daa9e92 | 527 | .I /proc/sys/fs/inotify/max_user_watches |
31546b46 VN |
528 | This specifies an upper limit on the number of watches |
529 | that can be created per real user ID. | |
47297adb | 530 | .SH VERSIONS |
2b2581ee MK |
531 | Inotify was merged into the 2.6.13 Linux kernel. |
532 | The required library interfaces were added to glibc in version 2.4. | |
533 | .RB ( IN_DONT_FOLLOW , | |
534 | .BR IN_MASK_ADD , | |
535 | and | |
536 | .B IN_ONLYDIR | |
64aa9bcb | 537 | were added in glibc version 2.5.) |
47297adb | 538 | .SH CONFORMING TO |
8382f16d | 539 | The inotify API is Linux-specific. |
47297adb | 540 | .SH NOTES |
4d2b74dd MK |
541 | Inotify file descriptors can be monitored using |
542 | .BR select (2), | |
543 | .BR poll (2), | |
c13182ef | 544 | and |
2315114c | 545 | .BR epoll (7). |
0000daa5 MK |
546 | When an event is available, the file descriptor indicates as readable. |
547 | ||
548 | Since Linux 2.6.25, | |
549 | signal-driven I/O notification is available for inotify file descriptors; | |
550 | see the discussion of | |
551 | .B F_SETFL | |
552 | (for setting the | |
553 | .B O_ASYNC | |
554 | flag), | |
555 | .BR F_SETOWN , | |
556 | and | |
557 | .B F_SETSIG | |
558 | in | |
559 | .BR fcntl (2). | |
560 | The | |
561 | .I siginfo_t | |
562 | structure (described in | |
563 | .BR sigaction (2)) | |
564 | that is passed to the signal handler has the following fields set: | |
565 | .IR si_fd | |
566 | is set to the inotify file descriptor number; | |
567 | .IR si_signo | |
568 | is set to the signal number; | |
569 | .IR si_code | |
570 | is set to | |
571 | .BR POLL_IN ; | |
572 | and | |
573 | .B POLLIN | |
574 | is set in | |
575 | .IR si_band . | |
4d2b74dd | 576 | |
c13182ef MK |
577 | If successive output inotify events produced on the |
578 | inotify file descriptor are identical (same | |
579 | .IR wd , | |
580 | .IR mask , | |
4d2b74dd MK |
581 | .IR cookie , |
582 | and | |
3f3698d8 | 583 | .IR name ), |
6f0ab035 MK |
584 | then they are coalesced into a single event if the |
585 | older event has not yet been read (but see BUGS). | |
8856aab8 MK |
586 | This reduces the amount of kernel memory required for the event queue, |
587 | but also means that an application can't use inotify to reliably count | |
588 | file events. | |
4d2b74dd | 589 | |
c13182ef MK |
590 | The events returned by reading from an inotify file descriptor |
591 | form an ordered queue. | |
592 | Thus, for example, it is guaranteed that when renaming from | |
593 | one directory to another, events will be produced in the | |
4d2b74dd MK |
594 | correct order on the inotify file descriptor. |
595 | ||
596 | The | |
597 | .B FIONREAD | |
63f6a20a | 598 | .BR ioctl (2) |
c13182ef | 599 | returns the number of bytes available to read from an |
4d2b74dd | 600 | inotify file descriptor. |
613836aa | 601 | .SS Limitations and caveats |
4d2b74dd MK |
602 | Inotify monitoring of directories is not recursive: |
603 | to monitor subdirectories under a directory, | |
604 | additional watches must be created. | |
613836aa MK |
605 | This can take a significant amount time for large directory trees. |
606 | ||
4d2ddb4e MK |
607 | The inotify API provides no information about the user or process that |
608 | triggered the inotify event. | |
99e603bd MK |
609 | In particular, there is no easy |
610 | way for a process that is monitoring events via inotify | |
611 | to distinguish events that it triggers | |
612 | itself from those that are triggered by other processes. | |
4d2ddb4e | 613 | |
613836aa MK |
614 | Note that the event queue can overflow. |
615 | In this case, events are lost. | |
09fa72fa | 616 | Robust applications should handle the possibility of |
613836aa MK |
617 | lost events gracefully. |
618 | ||
619 | The inotify API identifies affected files by filename. | |
620 | However, by the time an application processes an inotify event, | |
621 | the filename may already have been deleted or renamed. | |
622 | ||
623 | If monitoring an entire directory subtree, | |
031de152 MK |
624 | and a new subdirectory is created in that tree or an existing directory |
625 | is renamed into that tree, | |
613836aa | 626 | be aware that by the time you create a watch for the new subdirectory, |
031de152 | 627 | new files (and subdirectories) may already exist inside the subdirectory. |
613836aa | 628 | Therefore, you may want to scan the contents of the subdirectory |
031de152 MK |
629 | immediately after adding the watch (and, if desired, |
630 | recursively add watches for any subdirectories that it contains). | |
2f482041 MK |
631 | |
632 | The inotify applications identifies events via watch descriptors. | |
633 | It is the application's responsibility to cache a mapping | |
634 | (if one is needed) between watch descriptors and pathnames. | |
635 | Be aware that directory renamings may affect multiple cached pathnames. | |
47297adb | 636 | .SH BUGS |
a15ead5e MK |
637 | .\" FIXME kernel commit 611da04f7a31b2208e838be55a42c7a1310ae321 |
638 | .\" implies that unmount events were buggy 2.6.11 to 2.6.36 | |
639 | .\" | |
ed7b0235 MK |
640 | In kernels before 2.6.16, the |
641 | .B IN_ONESHOT | |
c13182ef | 642 | .I mask |
ed7b0235 | 643 | flag does not work. |
6f0ab035 | 644 | |
7b5151b7 MK |
645 | As originally designed and implemented, the |
646 | .B IN_ONESHOT | |
647 | flag did not cause an | |
648 | .B IN_IGNORED | |
649 | event to be generated when the watch was dropped after one event. | |
650 | However, as an unintended effect of other changes, | |
651 | since Linux 2.6.36, an | |
652 | .B IN_IGNORED | |
653 | event is generated in this case. | |
654 | ||
6f0ab035 | 655 | Before kernel 2.6.25, |
22129aa9 | 656 | .\" commit 1c17d18e3775485bf1e0ce79575eb637a94494a2 |
9ed6b517 | 657 | the kernel code that was intended to coalesce successive identical events |
6f0ab035 MK |
658 | (i.e., the two most recent events could potentially be coalesced |
659 | if the older had not yet been read) | |
660 | instead checked if the most recent event could be coalesced with the | |
661 | .I oldest | |
662 | unread event. | |
47297adb | 663 | .SH SEE ALSO |
f0afb16a MK |
664 | .BR inotifywait (1), |
665 | .BR inotifywatch (1), | |
4d2b74dd MK |
666 | .BR inotify_add_watch (2), |
667 | .BR inotify_init (2), | |
43bb5faf | 668 | .BR inotify_init1 (2), |
4d2b74dd MK |
669 | .BR inotify_rm_watch (2), |
670 | .BR read (2), | |
173fe7e7 DP |
671 | .BR stat (2) |
672 | ||
673 | .IR Documentation/filesystems/inotify.txt | |
674 | in the Linux kernel source tree |