函式介紹
本文僅僅將open
系統呼叫的使用簡單總結一下,關於其實現原理大批的大佬分享可以自行學習。open系統呼叫主要用於開啟或者建立乙個檔案,並返回檔案描述符。
以上兩個函式引數含義如下:
返回值 作業系統會為當前程序從3開始分配乙個未使用的檔案描述符,因為0,1,2已經被stdin
,stdout
,stderr
三個預設開啟的檔案占用。
函式使用
輸出如下:#include
#include
#include
#include
#include
#include
intmain
(int argc,
char
*ar**)
umask(0
);//這裡關於檔案不存在,則建立時賦予檔案的許可權兩種方式是一樣的,這裡賦予的是00770許可權
//fd=open(ar**[1],o_creat | o_rdwr, s_irwxu|s_irwxg);
fd=open
(ar**[1]
,o_creat | o_rdwr,
0770);
printf
("%d\n"
,fd)
;close
(fd)
;return0;
}
zhang@ubuntu:
~/test$ gcc test_open.c
zhang@ubuntu:
~/test$ .
/a.out test.txt
3zhang@ubuntu:
~/test$ ls -l test.txt
-rwxrwx--
-1 zhang zhang 0 sep 1503:
37 test.txt
Linux檔案程式設計之 系統呼叫 open
1 相關函式說明 函式原型 int open const char pathname,int flags int open constchar pathname,int flags,mode t mode 如果使用了o creat標誌,則要使用這個函式,這時需要指定mode來表示檔案的訪問許可權 相...
系統呼叫Open 函式的核心追蹤 上篇
from open函式相信大家都用過,這裡就不多說它的使用方法等事項,現直接進入正題.使用者態程式呼叫open函式時,會產生乙個中斷號為5的中斷請求,其值以該巨集 nr open進行標示.而後該程序上下文 processcontext 將會被切換到核心空間。待核心中的相關操作完成後,就會從核心返回,...
creat 與open 系統呼叫
creat 建立檔案,顯然引數只需要 路徑path,許可權mode 1 如果檔案存在怎麼辦?直接覆蓋掉!不管你裡面有沒有內容。include include include includeusing namespace std int main 建立成功,但是有個問題。給的許可權八進位制777最大許...