libuv onchang example
不同OS,低層採用不同方式來處理inotify
inotify on Linux, FSEvents on Darwin, kqueue on BSDs, ReadDirectoryChangesW on Windows, event ports on Solaris, unsupported on Cygwin
更新記錄
item | note |
---|---|
20160516 | 第一版 |
目錄
libuv onchang example
範例說明
- 參考來源
- All modern operating systems provide APIs to put watches on individual files or directories and be informed when the files are modified.
- The file change notification is started using uv_fs_event_init():
- int uv_fs_event_start(handle,cb,path,flags)
- path: 可以為檔案或目錄
- flags: 目前只有UV_FS_EVENT_RECURSIVE,當目錄或檔案有變更即通知
- example code
範例內容
1 | void run_command(uv_fs_event_t *handle, const char *filename, int events, int status) { |
範例測試
- 設定command:ls ,檢查Makefiel是否有變更
- 試著修改Makefile,產生3次的rename及1次的onchang
1 | [ubuntu](master-de06992)0h9m root@e8b0cd737680:[t05_onchange]$ ./t05-main-ubuntu ls Makefile |