Skip to Content
LINUX系統程式設計 第二版
book

LINUX系統程式設計 第二版

by Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from LINUX系統程式設計 第二版
檔案與目錄的管理
|
303
讓我們初始化 inotify,這樣我們才可以在後續的步驟使用它:
int fd;
fd = inotify_init1 (0);
if (fd ==
1) {
perror ("inotify_init1");
exit (EXIT_FAILURE);
}
檢視項目
一個行程初始化 inotify 後,接著會設置
檢視項目
watches
)。一個檢視項目(會被表示
成一個
檢視描述器
watch descriptor
))就是一個標準的 Unix 路徑,以及一個相對應的
檢視遮罩
watch mask
),可用於告知核心,行程感興趣的是哪些事件—例如,讀取、
寫入或此二者。
inotify 可以檢視檔案與目錄。如果要檢視一個目錄,inotify 會報告該目錄(以及該目
錄中所包含的任何檔案)之上所發生的事件(但是不包含被檢視目錄中之子目錄裡的檔
案—檢視操作不具遞迴性)。
加入一個新的檢視項目
系統呼叫
inotify_add_watch()
可以為檔案或目錄
path
上之
mask
所描述的事件,加入一
個檢視項目至
fd
所表示的 inotify 實例:
#include <sys/inotify.h>
int inotify_add_watch (int fd,
const char *path,
uint32_t mask);
執行成功時,
inotify_add_watch()
會傳回一個新的檢視描述器。執行失敗時,此呼叫會
傳回
-1
,並且會把
errno
設定為下面其中一個值:
EACCESS
不允許讀取 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769812