這章內容就是「provides a whirlwind tour of the UNIX System from a programmer's perspective」。shell
其實在看這章內容的時候,已經先看過了Chapter7~Chapter13,回頭再看看這樣的綜述介紹。多線程
1.2 UNIX Architectureapp
主要就瞭解下面這張圖便可:ide
在通常UNIX operating system中誰在哪層來調用誰。函數
1.3 Logging Inui
操做系統根據/etc/passwd中的信息來判斷logging in信息是否匹配。spa
每一行表明一個用戶登陸信息,舉例:操作系統
通常分爲七個部分,用冒號分割:線程
login name3d
encrypted password
numeric user ID
numeric group ID
a comment field(這個field在例子中爲空)
home directory
shell programm
1.4 Files and Directories
這個部分給出了第一份代碼的例子。經過這個20行代碼的例子,交代了很多東西:
man命令怎麼用
頭文件apue.h是幹啥的
錯誤處理函數err_sys和err_quit函數都是幹啥的
...
看了以後,給個人感受是做者安排每一個例子都是用心的,尤爲在書一開始的地方都把一些書上以後經常使用的內容交代清楚,讓人看的很明白。
1.5 Input and Output
(1)File Descriptors定義(先記着,有個念想): "normally small non-negative integers that the kernel uses to identify the files accessed by a process. Whenever it opens an existing file or creates a new file, the kernel returns a file descriptor that we use when we want to read or write the file."
(2)Standard Input , Standard Output & Standard Error
(3)Unbuffered I/O:open read write lseek close都是,而且這些函數都跟file descriptors協做。看到這裏對書上的例子瞬間產生了一個誤解:不是說是unbuffered了麼,怎麼還有read(STDIN_FILENO, buf, BUFFSIZE)這樣的形式呢?我沒有看事後面的部分,可是猜想這裏說的unbuffered是不用fflush刷新緩衝區的,具體的後面再看。
(4)Standard I/O:就是提供了一個buffered的接口來調用各類unbuffered I/O函數,函數包含在頭文件<stdio.h>中。
1.6 Programs and Processes
(1)Program:磁盤上的可執行文件;執行的時候先讀入內存,而後由kernel調用exec函數執行之。
(2)Processes and Process ID:正在執行的program示例就叫process;unix系統的進程號非負整數
(3)Process Control:fork ,exec, waitpid
(4)Thread and Thread IDs
1.7 Error Handling
(1)通常遇到error了,unix系統就返回一個負整數;不一樣的負整數標示不一樣類型的錯誤
(2)<errno.h>頭文件中有「symbol errno and constants for each value that errno can assume」,每一個符號都以E開頭;能夠用man 3 errno來查看具體表明意思。
(3)考慮到多線程的狀況,是貢獻進程中的address space的,每一個線程要有獨立的errno就須要其餘的定義方法,以下圖:
具體參考的是/usr/includes/bits/errno.h頭文件中的定義
(4)strerror函數把錯誤變量映射到錯誤信息字符串;perror能夠接受一個參數(通常是program的名),並將出錯信息輸出到standard error上。
(5)error recovery。fatal error麼有recovery action;nonfatal error有recovery action。跟資源相關的nonfatal error的recovery的策略分兩種:一種是等;一種是重試。
1.8 User Identification
1.9 Sginals
Signals are a technique used to notify a process that some condition has occurred
1.10 Time Values
unix系統有兩類不一樣的時間變量:
(1)Calendar time:1970.1.1零點開始到如今的秒數
(2)Process time:CPU time(在多線程那章的時候用到過)
注意相對時間和絕對時間;另外若是是多核的條件,時間統計時候與單核的狀況可能不同
1.11 System Calls and Library Functions
具體能夠參照1.2中的那張圖理解。對於application的級別來講,便可以直接用system call也能夠用libarary functions。
書上舉了一個內存分配的malloc(2)函數與sbrk(3)的例子。