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系統程式設計 第二版
282
|
第八章
一個行程如果不在乎它的當前工作目錄為何—例如監控程式(daemon)—通常會叫用
chdir(/)
把它設定成
/
。一個介接用戶與資料的應用程式,例如文書處理器,通常會
把它的當前工作目錄設定成用戶的 home 目錄,或者是特定的文件目錄。因為當前工作
目錄僅與相對路徑名稱的語境有關,所以就「用戶從 shell 所調用的命令列公用程式」
而言,當前工作目錄最為有用。
建立目錄
Linux 提供了一個經 POSIX 標準化的系統呼叫,可用於建立新目錄:
#include <sys/stat.h>
#include <sys/types.h>
int mkdir (const char *path, mode_t mode);
執行成功時,
mkdir()
所建立的目錄
path
(可能是相對的,也可能是絕對的),具有權限
位元
mode
(經過當前 umask 的修改),而且會傳回
0
當前的 umask 會按照通常的方式修改
mode
引數,再加上作業系統特有的模式位元。
Linux 中,新建目錄的權限位元會被設定為
(mode & ~umask & 01777)
。換言之,事實
上,umask 對行程所強加的限制是
mkdir()
所不能忽視的。如果新目錄之父目錄的 set
group ID
sgid
)位元有被設定,或者檔案系統的掛載使用了 BSD 的群組語義,則新目
錄將從它的父目錄繼承此群組關係。否則,會對新目錄使用行程的有效群組識別碼。
執行失敗時,
mkdir()
會傳回
-1
並且會把
errno
設定為下面其中一個值: ...
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

深入理解運算原理|從簡單的機器到無所不能的程式

深入理解運算原理|從簡單的機器到無所不能的程式

Tom Stuart
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
算法技术手册(原书第2 版)

算法技术手册(原书第2 版)

George T.Heineman, Gary Pollice, Stanley Selkow

Publisher Resources

ISBN: 9789862769812