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系統程式設計 第二版
302
|
第八章
使用 inotify,核心可以在事件發生的瞬間通知應用程式。檔案一被刪除,核心就會通知
檔案管理程式。而檔案管理程式的回應就是,立即從目錄的圖形化顯示中移除被刪除的
檔案。
多數其他的應用程式也會對檔案事件感興趣。考慮一個備份公用程式或是一個資料索引
工具。inotify 讓這兩個程式得以即時操作:在一個檔案被建立、刪除或寫入的瞬間,這
兩個工具分別可以更新備份包裝檔(backup archive)或資料索引(data index)。
inotify 用於取代
dnotify
這個採用麻煩之信號介面的較早期檔案監視機制。相較於
dnotify,應用程式應該優先採用 inotifyinotify,引進自核心 2.6.13 版,不但有彈性而
且容易使用,因為程式對正規檔案所進行操作可以跟 inotify 一起運作。本書只會提到
inotify
初始化 inotify
在一個行程可以使用 inotify 之前,該行程必須對它進行初始化。
inotify_init()
系統呼
叫可用於初始化 inotify 以及傳回一個「代表已初始化之實例的」檔案描述器:
#include <sys/inotify.h>
int inotify_init1 (int flags);
flags
參數的值通常是
0
,但也可能是下面各旗標經逐位元 OR 運算的結果:
IN_CLOEXEC
在新的檔案描述器上設定
close-on-exec
旗標。
IN_NONBLOCK
在新的檔案描述器上設定
O_NONBLOCK
旗標。
發生錯誤時,
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