--- tags: cs:app --- # [CS:APP](https://hackmd.io/@sysprog/CSAPP) 第 10 章重點提示 ## 導讀 * [你所不知道的 C 語言: Stream I/O 和 EOF](https://hackmd.io/s/Sy8pJ0x9G) ## System-Level I/O * [投影片](https://www.cs.cmu.edu/~213/lectures/16-io.pdf) / [錄影](https://scs.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=f107c2ce-79d5-4529-baeb-2bb495d8c11a) ![](https://i.imgur.com/01IghIa.png) ![](https://i.imgur.com/uRhNCv4.png) UNIX 設計哲學: "[Everything is a file](https://en.wikipedia.org/wiki/Everything_is_a_file)" * 更精確來說是 "Everything is a file descriptor" * But file descriptors are also created for things like anonymous pipes and network sockets via different methods ==Page 622 - Page 623== 搭配下圖理解 Linux 網路架構: ![](https://i.imgur.com/KuCvEQY.png) 延伸閱讀: [In UNIX Everything is a File](https://hackmd.io/@jkyang/unix-everything-is-a-file) ![](https://i.imgur.com/aH0sUwl.png) ![](https://i.imgur.com/AdNubcj.png) End of line (EOL) indicators in other systems * Linux and macOS: `\n` (0xa): line feed (LF) * Windows and Internet protocols: `\r\n` (0xd 0xa): Carriage return (CR) followed by line feed (LF) ![](https://i.imgur.com/Mmbjrbj.png) ![](https://i.imgur.com/0R1xkew.png) ==Page 627 - Page 631== * [Reentrant vs Thread-safe: Part 1](http://magicjackting.pixnet.net/blog/post/113860339) * [Reentrant vs Thread-safe: Part 2](http://magicjackting.pixnet.net/blog/post/113859925) * [Reentrant vs Thread-safe: Part 3](http://magicjackting.pixnet.net/blog/post/117448003) ![](https://i.imgur.com/MgsCGKE.png) ![](https://i.imgur.com/CnM3YBh.png) ![](https://i.imgur.com/2VAwoYH.png) Pros and Cons of Unix I/O ==slides p.51-54, p.56-58== ## 自我檢查清單 - [ ] tty 是什麼?緣起為何?對 UNIX 的影響又是? - [ ] 為何 socket 也是一種 file type 呢?具體使用方式為何? - [ ] RIO package 提供 I/O 封裝的目的為何?對應到真實世界的應用為何? - [ ] Buffered I/O 的動機和效益為何? - [ ] 在 `fork` 系統呼叫後,child process 和 parent process 的檔案分享狀況為何?(提示:閱讀 man-pages)