---
hackpadID: gnQyhcXcjtT
hackpadWorkspace: tossug
tags: hackpad-import, tossug
---
# Linux 讀書會 - 第 13 週 10/28/2014
###### tags: `TOSSUG 讀書會`
總目錄 [edX Introduction to Linux](https://tossug.hackpad.com/dVX1LvoCcii)
## 課程筆記
**Section 1**
Process: 執行中的程式
Thread: 輕量級 process
* Scheduler在分配cpu time的時候是以thread為基本單位,每個process至少會有一個thread ?!
* 是的,每個process在kernel scheduler的認知上只是一組用相同address space的threads,應該說kernel scheduler根本不用知道single-thread process和它的thread的分別,它只要排task
[TCB](https://en.wikipedia.org/wiki/Thread_control_block) 和 [PCB](https://en.wikipedia.org/wiki/Process_control_block) 儲存 thread 和 process 的必要資訊。
<undefined>* **Scheduling**</undefined>
[](https://en.wikipedia.org/wiki/Scheduling_(computing))[https://en.wikipedia.org/wiki/Scheduling_(computing](https://en.wikipedia.org/wiki/Scheduling_%28computing)[)](https://en.wikipedia.org/wiki/Scheduling_%28computing%29)
[](http://mmdays.com/2007/09/28/cpu_scheduling/)[http://mmdays.com/2007/09/28/cpu_scheduling/](http://mmdays.com/2007/09/28/cpu_scheduling/)
[](http://www.tutorialspoint.com/operating_system/os_process_scheduling_algorithms.htm)[http://www.tutorialspoint.com/operating_system/os_process_scheduling_algorithms.htm](http://www.tutorialspoint.com/operating_system/os_process_scheduling_algorithms.htm)
<undefined>* **Process scheduler**</undefined>
* long-term sheduling
* mid-term sheduling
* short-term sheduling
<undefined>* **Scheduling algorithm**</undefined>
對 process 進行分工,決定每個 process 切成幾份 task,每個 task 分到多少 CPU time。
* First-Come-First-Served (FCFS)
* Shortest-Job-First (SJF)
* 不可能實作,因為若事先知道時間,就不用排程演算法了。
* Priority
* Each process is assigned a priority. Process with highest priority is to be executed first and so on.
* Processes with same priority are executed on first come first serve basis.
* Priority can be decided based on memory requirements, time requirements or any other resource requirement.
* Round Robin (RR)
* 透過 quantum 值決定每個 task 分到多少時間。
* Multi Queue
* 依用途分成不同的 queue,可各自套用不同的演算法。
Linux kernel 預設使用 [CFS](https://en.wikipedia.org/wiki/Completely_Fair_Scheduler) 排程演算法,透過[紅黑樹](https://en.wikipedia.org/wiki/Red–black_tree)儲存記錄 task,時間複雜度為 O(log n)。
Ref: [](http://en.wikipedia.org/wiki/Completely_Fair_Scheduler)http://en.wikipedia.org/wiki/Completely_Fair_Scheduler
<undefined>* **基本觀念複習**</undefined>
*
nice value, niceness:
好人值,數值愈高,優先權愈低。
Resource starvation
永遠有 process 執行不到。
[](https://en.wikipedia.org/wiki/Resource_starvation)[https://en.wikipedia.org/wiki/Resource_starvation](https://en.wikipedia.org/wiki/Resource_starvation)
**Section 2**
ps aux
ps axo
top 以外的監控工具:
* htop: [](http://hisham.hm/htop/)[http://hisham.hm/htop/](http://hisham.hm/htop/)
* atop(OS X 不支援): [](http://www.atoptool.nl/)[http://www.atoptool.nl/](http://www.atoptool.nl/)
* nmon(OS X 不支援): [](http://nmon.sourceforge.net/pmwiki.php)[http://nmon.sourceforge.net/pmwiki.php](http://nmon.sourceforge.net/pmwiki.php)
* vtop: [](http://parall.ax/vtop)[http://parall.ax/vtop](http://parall.ax/vtop)
* iotop: [](http://guichaz.free.fr/iotop/)[http://guichaz.free.fr/iotop/](http://guichaz.free.fr/iotop/)
* iftop: [](http://www.ex-parrot.com/pdw/iftop/)[http://www.ex-parrot.com/pdw/iftop/](http://www.ex-parrot.com/pdw/iftop/)
top -Hp pid -> 監控某個process下所有thread的CPU Usage (Application can use it to tune performance)
* 非常實用!
kernel space
掛載 rootfs 前,切出一塊記憶體空間,用來識別和載入硬體資源 (driver, kernel modules, etc...),也就是進入系統後看到的 `/proc`。FreeBSD 和 Mac OS X 不建立 `/proc`,具體行為還沒研究。
user space
不屬於 kernel space,獨立一塊供使用者使用的記憶體空間。
## 本週作業
Chapter 17: Processes
* Section 3 - Section 4
## 活動簽到
[Carl Su](/ep/profile/n5euV0AaWLn)
[P Fisher](/ep/profile/oTOWRrYfPRk)
[Sam Lu](/ep/profile/zi86w39M6U6)
[violetson](/ep/profile/oJusv72f72w)
[Manuel Stallman](/ep/profile/GgkcGJEol5r)
[Kommodore Kezza](/ep/profile/CvxduB5FRRT)