Update 计算机操作系统 - 进程管理.md
重新绘制配图,补充上下文切换。
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 156 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 77 KiB |
|
After Width: | Height: | Size: 152 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 116 KiB |
@@ -6,6 +6,7 @@
|
||||
* [2. 线程](#2-线程)
|
||||
* [3. 区别](#3-区别)
|
||||
* [4. 协程](#4-协程)
|
||||
* [5. 上下文切换](#5-上下文切换)
|
||||
* [进程状态的切换](#进程状态的切换)
|
||||
* [进程调度算法](#进程调度算法)
|
||||
* [1. 批处理系统](#1-批处理系统)
|
||||
@@ -26,6 +27,7 @@
|
||||
* [4. 信号量](#4-信号量)
|
||||
* [5. 共享存储](#5-共享存储)
|
||||
* [6. 套接字](#6-套接字)
|
||||
* [参考资料](#参考资料)
|
||||
<!-- GFM-TOC -->
|
||||
|
||||
|
||||
@@ -37,9 +39,9 @@
|
||||
|
||||
进程控制块 (Process Control Block, PCB) 描述进程的基本信息和运行状态,所谓的创建进程和撤销进程,都是指对 PCB 的操作。
|
||||
|
||||
下图显示了 4 个程序创建了 4 个进程,这 4 个进程可以并发地执行。
|
||||
下图显示了 4 个进程在一个 CPU 上并发地执行。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/a6ac2b08-3861-4e85-baa8-382287bfee9f.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/process-concurrent.png" width="740px"/> </div><br>
|
||||
|
||||
### 2. 线程
|
||||
|
||||
@@ -49,7 +51,7 @@
|
||||
|
||||
QQ 和浏览器是两个进程,浏览器进程里面有很多线程,例如 HTTP 请求线程、事件响应线程、渲染线程等等,线程的并发执行使得在浏览器中点击一个新链接从而发起 HTTP 请求时,浏览器还可以响应用户的其它事件。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/3cd630ea-017c-488d-ad1d-732b4efeddf5.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/process-threads.png" width="740px"/> </div><br>
|
||||
|
||||
### 3. 区别
|
||||
|
||||
@@ -81,9 +83,23 @@ QQ 和浏览器是两个进程,浏览器进程里面有很多线程,例如 H
|
||||
|
||||
Java 21 正式引入的虚拟线程([JEP 444](https://openjdk.org/jeps/444))就是 JVM 实现的协程:虚拟线程由 JVM 调度到少量的平台线程上运行,执行阻塞 I/O 时从平台线程上卸载,让平台线程去执行其它虚拟线程。虚拟线程的创建成本很低,不需要用线程池复用,需要限制并发数时使用信号量。在 JDK 21 中,虚拟线程在 synchronized 块内阻塞时无法卸载,JDK 24 起([JEP 491](https://openjdk.org/jeps/491))基本消除了这个限制。
|
||||
|
||||
### 5. 上下文切换
|
||||
|
||||
上下文切换指的是 CPU 从执行一个线程改为执行另一个线程时,把当前线程的寄存器、程序计数器、栈指针等保存起来,再恢复另一个线程上次保存的值。以下情况会发生上下文切换:
|
||||
|
||||
- 时间片用完,被调度程序换下;
|
||||
- 线程主动阻塞,例如等待 I/O、等待锁、调用 sleep();
|
||||
- 更高优先级的线程进入就绪状态。
|
||||
|
||||
需要注意的是,系统调用只是从用户态进入内核态,执行完后通常回到同一个线程,不一定发生上下文切换。
|
||||
|
||||
同一进程中的线程切换不需要换地址空间;切换到另一个进程时还要切换页表,TLB 和 CPU 缓存中原来的地址映射和数据对新进程没有用,要重新加载,这部分间接开销通常比保存寄存器更大。
|
||||
|
||||
在 Linux 容器中用 taskset 把两个执行流固定在同一个 CPU 上,通过两根管道来回传 1 个字节,让它们交替运行:两个线程之间、两个进程之间每次切换都约 1.1 微秒(包含一次 read 或 write 系统调用)。数据量很小时两者几乎没有差别,进程切换的额外开销主要在工作集较大时体现出来。线程过多、频繁阻塞时,CPU 会把相当一部分时间花在切换上,可以用 vmstat 的 cs 列或 pidstat -w 观察每秒的切换次数。
|
||||
|
||||
## 进程状态的切换
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ProcessState.png" width="500"/> </div><br>
|
||||
<div align="center"> <img src="pics/process-states.png" width="720px"/> </div><br>
|
||||
|
||||
- 就绪状态(ready):等待被调度
|
||||
- 运行状态(running)
|
||||
@@ -131,7 +147,7 @@ Java 21 正式引入的虚拟线程([JEP 444](https://openjdk.org/jeps/444))
|
||||
- 因为进程切换都要保存进程的信息并且载入新进程的信息,如果时间片太小,会导致进程切换得太频繁,在进程切换上就会花过多时间。
|
||||
- 而如果时间片过长,那么实时性就不能得到保证。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/8c662999-c16c-481c-9f40-1fdba5bc9167.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/process-rr.png" width="740px"/> </div><br>
|
||||
|
||||
**2.2 优先级调度**
|
||||
|
||||
@@ -149,7 +165,7 @@ Java 21 正式引入的虚拟线程([JEP 444](https://openjdk.org/jeps/444))
|
||||
|
||||
可以将这种调度算法看成是时间片轮转调度算法和优先级调度算法的结合。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/042cf928-3c8e-4815-ae9c-f2780202c68f.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/process-mlfq.png" width="740px"/> </div><br>
|
||||
|
||||
### 3. 实时系统
|
||||
|
||||
@@ -323,7 +339,7 @@ end;
|
||||
|
||||
### 1. 哲学家进餐问题
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/a9077f06-7584-4f2b-8c20-3a8e46928820.jpg"/> </div><br>
|
||||
<div align="center"> <img src="pics/philosophers.png" width="720px"/> </div><br>
|
||||
|
||||
五个哲学家围着一张圆桌,每个哲学家面前放着食物。哲学家的生活有两种交替活动:吃饭以及思考。当一个哲学家吃饭时,需要先拿起自己左右两边的两根筷子,并且一次只能拿起一根筷子。
|
||||
|
||||
@@ -568,7 +584,7 @@ int pipe(int fd[2]);
|
||||
- 只支持半双工通信(单向交替传输);
|
||||
- 只能在父子进程或者兄弟进程中使用。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/53cd9ade-b0a6-4399-b4de-7f1fbd06cdfb.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/pipe.png" width="740px"/> </div><br>
|
||||
|
||||
### 2. FIFO
|
||||
|
||||
@@ -582,7 +598,7 @@ int mkfifoat(int fd, const char *path, mode_t mode);
|
||||
|
||||
FIFO 常用于客户-服务器应用程序中,FIFO 用作汇聚点,在客户进程和服务器进程之间传递数据。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/2ac50b81-d92a-4401-b9ec-f2113ecc3076.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/fifo.png" width="720px"/> </div><br>
|
||||
|
||||
### 3. 消息队列
|
||||
|
||||
@@ -607,3 +623,8 @@ FIFO 常用于客户-服务器应用程序中,FIFO 用作汇聚点,在客户
|
||||
### 6. 套接字
|
||||
|
||||
与其它通信机制不同的是,它可用于不同机器间的进程通信。
|
||||
|
||||
## 参考资料
|
||||
|
||||
- Tanenbaum A S, Bos H. Modern Operating Systems [M]. Pearson, 2014.
|
||||
- [pipe(7) — Linux manual page](https://man7.org/linux/man-pages/man7/pipe.7.html)
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="260" viewBox="0 0 720 260">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="360" y="28" class="title">FIFO:不相关的进程通过路径名通信</text>
|
||||
<rect x="30" y="60" width="140" height="36" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="100" y="82.5" class="c sub">客户进程 1</text>
|
||||
<line x1="172" y1="78" x2="296" y2="128" class="arrow "/>
|
||||
<rect x="30" y="116" width="140" height="36" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="100" y="138.5" class="c sub">客户进程 2</text>
|
||||
<line x1="172" y1="134" x2="296" y2="128" class="arrow "/>
|
||||
<rect x="30" y="172" width="140" height="36" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="100" y="194.5" class="c sub">客户进程 3</text>
|
||||
<line x1="172" y1="190" x2="296" y2="128" class="arrow "/>
|
||||
<path d="M300,100 h35 l9,9 v47 h-44 z" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<path d="M335,100 v9 h9" fill="none" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<line x1="306" y1="117" x2="337" y2="117" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<line x1="306" y1="124" x2="337" y2="124" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<line x1="306" y1="131" x2="337" y2="131" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="322" y="176" class="c sub mono">/tmp/server.fifo</text>
|
||||
<line x1="350" y1="128" x2="476" y2="128" class="arrow "/>
|
||||
<rect x="480" y="110" width="140" height="36" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="550" y="132.5" class="c sub b">服务器进程</text>
|
||||
<text x="30" y="240" class="sub">mkfifo 在文件系统中创建一个特殊文件,任何有权限的进程都可以打开它读写,数据仍然经过内核,不写入磁盘。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,68 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="320" viewBox="0 0 720 320">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="360" y="28" class="title">哲学家进餐:5 个人、5 根筷子</text>
|
||||
<circle cx="200" cy="170" r="90" fill="#EAE9E7" stroke="#BFBEBA"/>
|
||||
<circle cx="200" cy="46" r="20" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="200" y="50" class="c sub b" style="fill:#444">P0</text>
|
||||
<circle cx="200" cy="106" r="12" fill="#FFFFFF" stroke="#BBB"/>
|
||||
<line x1="229.389" y1="129.549" x2="249.374" y2="102.043" stroke="#8A6D5A" stroke-width="3" stroke-linecap="round"/>
|
||||
<text x="221.16" y="144.875" class="c sub mono">0</text>
|
||||
<circle cx="317.931" cy="131.682" r="20" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="317.931" y="135.682" class="c sub b" style="fill:#444">P1</text>
|
||||
<circle cx="260.868" cy="150.223" r="12" fill="#FFFFFF" stroke="#BBB"/>
|
||||
<line x1="247.553" y1="185.451" x2="279.889" y2="195.957" stroke="#8A6D5A" stroke-width="3" stroke-linecap="round"/>
|
||||
<text x="234.238" y="185.125" class="c sub mono">1</text>
|
||||
<circle cx="272.885" cy="270.318" r="20" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="272.885" y="274.318" class="c sub b" style="fill:#444">P2</text>
|
||||
<circle cx="237.618" cy="221.777" r="12" fill="#FFFFFF" stroke="#BBB"/>
|
||||
<line x1="200" y1="220" x2="200" y2="254" stroke="#8A6D5A" stroke-width="3" stroke-linecap="round"/>
|
||||
<text x="200" y="210" class="c sub mono">2</text>
|
||||
<circle cx="127.115" cy="270.318" r="20" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="127.115" y="274.318" class="c sub b" style="fill:#444">P3</text>
|
||||
<circle cx="162.382" cy="221.777" r="12" fill="#FFFFFF" stroke="#BBB"/>
|
||||
<line x1="152.447" y1="185.451" x2="120.111" y2="195.957" stroke="#8A6D5A" stroke-width="3" stroke-linecap="round"/>
|
||||
<text x="165.762" y="185.125" class="c sub mono">3</text>
|
||||
<circle cx="82.069" cy="131.682" r="20" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="82.069" y="135.682" class="c sub b" style="fill:#444">P4</text>
|
||||
<circle cx="139.132" cy="150.223" r="12" fill="#FFFFFF" stroke="#BBB"/>
|
||||
<line x1="170.611" y1="129.549" x2="150.626" y2="102.043" stroke="#8A6D5A" stroke-width="3" stroke-linecap="round"/>
|
||||
<text x="178.84" y="144.875" class="c sub mono">4</text>
|
||||
<text x="400" y="80" class="b">如果每个人都先拿编号与自己相同的筷子:</text>
|
||||
<text x="400" y="106" class="sub" style="fill:#444">P0 拿 0、P1 拿 1……P4 拿 4,再去拿另一根:</text>
|
||||
<text x="400" y="126" class="sub note">P0 等 4、P1 等 0……P4 等 3,形成环路,死锁。</text>
|
||||
<text x="400" y="166" class="b">解决方法:</text>
|
||||
<text x="400" y="190" class="sub" style="fill:#444">① 只有左右两根都能拿到时才拿(下面的代码);</text>
|
||||
<text x="400" y="210" class="sub" style="fill:#444">② 都先拿编号小的那根:P0 改为先拿 0 再拿 4,</text>
|
||||
<text x="400" y="230" class="sub" style="fill:#444"> 与 P1 争抢 0,环路被打破;</text>
|
||||
<text x="400" y="250" class="sub" style="fill:#444">③ 最多允许 4 个人同时拿筷子。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.5 KiB |
@@ -0,0 +1,54 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="300" viewBox="0 0 740 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="370" y="28" class="title">管道:fork 之后父进程写、子进程读</text>
|
||||
<rect x="30" y="50" width="250" height="110" rx="8" class="frame"/>
|
||||
<text x="40" y="68" class="b">父进程</text>
|
||||
<rect x="460" y="50" width="250" height="110" rx="8" class="frame"/>
|
||||
<text x="470" y="68" class="b">子进程</text>
|
||||
<rect x="50" y="86" width="100" height="30" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="100" y="105" class="c sub" style="fill:#444">fd[1] 写端</text>
|
||||
<rect x="160" y="86" width="100" height="30" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="210" y="105" class="c sub" style="fill:#444">fd[0] 关闭</text>
|
||||
<rect x="480" y="86" width="100" height="30" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="530" y="105" class="c sub" style="fill:#444">fd[0] 读端</text>
|
||||
<rect x="590" y="86" width="100" height="30" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="640" y="105" class="c sub" style="fill:#444">fd[1] 关闭</text>
|
||||
<rect x="290" y="210" width="160" height="44" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="370" y="230" class="c sub b" style="fill:#444">内核中的管道缓冲区</text>
|
||||
<text x="370" y="246" class="c sub">Linux 默认 64 KB</text>
|
||||
<path d="M100,118 C100,190 220,232 286,232" class="arrow"/>
|
||||
<path d="M454,232 C520,232 530,190 530,120" class="arrow"/>
|
||||
<text x="150" y="200" class="sub mono">write(fd[1], "hello")</text>
|
||||
<text x="560" y="200" class="sub mono">read(fd[0], buf)</text>
|
||||
<text x="30" y="286" class="sub">pipe 返回两个文件描述符,fork 后父子进程都持有两端,各自关闭不用的一端,数据只能单向流动。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.3 KiB |
@@ -0,0 +1,57 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="260" viewBox="0 0 740 260">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="370" y="28" class="title">4 个进程在一个 CPU 上并发执行</text>
|
||||
<text x="60" y="78" class="sub b e" style="fill:#444">进程 A</text>
|
||||
<line x1="70" y1="73" x2="700" y2="73" stroke="#EEE"/>
|
||||
<text x="60" y="114" class="sub b e" style="fill:#444">进程 B</text>
|
||||
<line x1="70" y1="109" x2="700" y2="109" stroke="#EEE"/>
|
||||
<text x="60" y="150" class="sub b e" style="fill:#444">进程 C</text>
|
||||
<line x1="70" y1="145" x2="700" y2="145" stroke="#EEE"/>
|
||||
<text x="60" y="186" class="sub b e" style="fill:#444">进程 D</text>
|
||||
<line x1="70" y1="181" x2="700" y2="181" stroke="#EEE"/>
|
||||
<rect x="72" y="63" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="124" y="99" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="176" y="135" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="228" y="171" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="280" y="63" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="332" y="99" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="384" y="135" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="436" y="171" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="488" y="63" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="540" y="135" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="592" y="171" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<rect x="644" y="63" width="50" height="20" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<line x1="70" y1="206" x2="700" y2="206" class="line"/>
|
||||
<text x="700" y="224" class="sub e">时间</text>
|
||||
<text x="30" y="248" class="sub">任一时刻只有一个进程在 CPU 上运行;操作系统按时间片轮流切换,宏观上看 4 个进程在同时推进。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
@@ -0,0 +1,114 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="300" viewBox="0 0 740 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="370" y="28" class="title">多级反馈队列:一个需要 100 个时间片的进程</text>
|
||||
<text x="110" y="73" class="sub b e" style="fill:#444">队列 1</text>
|
||||
<rect x="120" y="56" width="220" height="24" rx="12" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<rect x="130" y="60" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="148.4" y="72" class="c sub"></text>
|
||||
<rect x="170.8" y="60" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="189.2" y="72" class="c sub"></text>
|
||||
<rect x="211.6" y="60" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="252.4" y="60" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="293.2" y="60" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<text x="352" y="73" class="sub">时间片 1</text>
|
||||
<text x="440" y="73" class="sub" style="">累计运行 1</text>
|
||||
<path d="M340,68 q12,0 12,16" fill="none" stroke="#BBB" marker-end="url(#a)"/>
|
||||
<text x="110" y="105" class="sub b e" style="fill:#444">队列 2</text>
|
||||
<rect x="120" y="88" width="220" height="24" rx="12" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<rect x="130" y="92" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="148.4" y="104" class="c sub"></text>
|
||||
<rect x="170.8" y="92" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="189.2" y="104" class="c sub"></text>
|
||||
<rect x="211.6" y="92" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="252.4" y="92" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="293.2" y="92" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<text x="352" y="105" class="sub">时间片 2</text>
|
||||
<text x="440" y="105" class="sub" style="">累计运行 3</text>
|
||||
<path d="M340,100 q12,0 12,16" fill="none" stroke="#BBB" marker-end="url(#a)"/>
|
||||
<text x="110" y="137" class="sub b e" style="fill:#444">队列 3</text>
|
||||
<rect x="120" y="120" width="220" height="24" rx="12" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<rect x="130" y="124" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="148.4" y="136" class="c sub"></text>
|
||||
<rect x="170.8" y="124" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="189.2" y="136" class="c sub"></text>
|
||||
<rect x="211.6" y="124" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="252.4" y="124" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="293.2" y="124" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<text x="352" y="137" class="sub">时间片 4</text>
|
||||
<text x="440" y="137" class="sub" style="">累计运行 7</text>
|
||||
<path d="M340,132 q12,0 12,16" fill="none" stroke="#BBB" marker-end="url(#a)"/>
|
||||
<text x="110" y="169" class="sub b e" style="fill:#444">队列 4</text>
|
||||
<rect x="120" y="152" width="220" height="24" rx="12" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<rect x="130" y="156" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="148.4" y="168" class="c sub"></text>
|
||||
<rect x="170.8" y="156" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="211.6" y="156" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="252.4" y="156" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="293.2" y="156" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<text x="352" y="169" class="sub">时间片 8</text>
|
||||
<text x="440" y="169" class="sub" style="">累计运行 15</text>
|
||||
<path d="M340,164 q12,0 12,16" fill="none" stroke="#BBB" marker-end="url(#a)"/>
|
||||
<text x="110" y="201" class="sub b e" style="fill:#444">队列 5</text>
|
||||
<rect x="120" y="184" width="220" height="24" rx="12" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<rect x="130" y="188" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="148.4" y="200" class="c sub"></text>
|
||||
<rect x="170.8" y="188" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="211.6" y="188" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="252.4" y="188" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="293.2" y="188" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<text x="352" y="201" class="sub">时间片 16</text>
|
||||
<text x="440" y="201" class="sub" style="">累计运行 31</text>
|
||||
<path d="M340,196 q12,0 12,16" fill="none" stroke="#BBB" marker-end="url(#a)"/>
|
||||
<text x="110" y="233" class="sub b e" style="fill:#444">队列 6</text>
|
||||
<rect x="120" y="216" width="220" height="24" rx="12" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<rect x="130" y="220" width="36.8" height="16" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1.2"/>
|
||||
<text x="148.4" y="232" class="c sub"></text>
|
||||
<rect x="170.8" y="220" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="211.6" y="220" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="252.4" y="220" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="293.2" y="220" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<text x="352" y="233" class="sub">时间片 32</text>
|
||||
<text x="440" y="233" class="sub" style="">累计运行 63</text>
|
||||
<path d="M340,228 q12,0 12,16" fill="none" stroke="#BBB" marker-end="url(#a)"/>
|
||||
<text x="110" y="265" class="sub b e" style="fill:#444">队列 7</text>
|
||||
<rect x="120" y="248" width="220" height="24" rx="12" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1.2"/>
|
||||
<rect x="130" y="252" width="36.8" height="16" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1.2"/>
|
||||
<text x="148.4" y="264" class="c sub"></text>
|
||||
<rect x="170.8" y="252" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="211.6" y="252" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="252.4" y="252" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<rect x="293.2" y="252" width="36.8" height="16" rx="3" fill="none" stroke="#CCC" stroke-dasharray="3 2"/>
|
||||
<text x="352" y="265" class="sub">时间片 64</text>
|
||||
<text x="440" y="265" class="sub" style="fill:#444">累计运行 100,完成</text>
|
||||
<text x="30" y="290" class="sub">没用完时间片就进入下一级。这个进程只被调度 7 次,而时间片固定为 1 时要调度 100 次;新来的短进程在上面的高优先级队列中很快完成。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 8.7 KiB |
@@ -0,0 +1,62 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="250" viewBox="0 0 740 250">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="370" y="28" class="title">时间片轮转:时间片为 2,A、B、C 分别需要运行 5、3、2</text>
|
||||
<rect x="60" y="70" width="124" height="34" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="122" y="91" class="c sub b" style="fill:#444">A</text>
|
||||
<rect x="184" y="70" width="124" height="34" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
|
||||
<text x="246" y="91" class="c sub b" style="fill:#444">B</text>
|
||||
<rect x="308" y="70" width="124" height="34" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="370" y="91" class="c sub b" style="fill:#444">C</text>
|
||||
<rect x="432" y="70" width="124" height="34" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="494" y="91" class="c sub b" style="fill:#444">A</text>
|
||||
<rect x="556" y="70" width="62" height="34" rx="3" fill="#C6ECE9" stroke="#7DBCB7" stroke-width="1"/>
|
||||
<text x="587" y="91" class="c sub b" style="fill:#444">B</text>
|
||||
<rect x="618" y="70" width="62" height="34" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="649" y="91" class="c sub b" style="fill:#444">A</text>
|
||||
<text x="60" y="122" class="c sub mono">0</text>
|
||||
<text x="122" y="122" class="c sub mono">1</text>
|
||||
<text x="184" y="122" class="c sub mono">2</text>
|
||||
<text x="246" y="122" class="c sub mono">3</text>
|
||||
<text x="308" y="122" class="c sub mono">4</text>
|
||||
<text x="370" y="122" class="c sub mono">5</text>
|
||||
<text x="432" y="122" class="c sub mono">6</text>
|
||||
<text x="494" y="122" class="c sub mono">7</text>
|
||||
<text x="556" y="122" class="c sub mono">8</text>
|
||||
<text x="618" y="122" class="c sub mono">9</text>
|
||||
<text x="680" y="122" class="c sub mono">10</text>
|
||||
<text x="432" y="150" class="c sub">C 在 6 结束</text>
|
||||
<text x="618" y="150" class="c sub">B 在 9 结束</text>
|
||||
<text x="680" y="166" class="c sub e">A 在 10 结束</text>
|
||||
<text x="30" y="200" class="sub">用完时间片的进程回到队尾。平均完成时间 (10 + 9 + 6) / 3 ≈ 8.3;时间片越小响应越快,但切换次数越多,</text>
|
||||
<text x="30" y="218" class="sub">每次切换都要保存和恢复上下文。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
@@ -0,0 +1,57 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="720" height="300" viewBox="0 0 720 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="360" y="28" class="title">进程状态的切换</text>
|
||||
<rect x="40" y="132" width="100" height="36" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
|
||||
<text x="90" y="154.5" class="c sub b">新建</text>
|
||||
<rect x="220" y="132" width="100" height="36" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="270" y="154.5" class="c sub b">就绪</text>
|
||||
<rect x="420" y="132" width="100" height="36" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="470" y="154.5" class="c sub b">运行</text>
|
||||
<rect x="320" y="232" width="100" height="36" rx="6" fill="#E6E3FA" stroke="#B8B0DE"/>
|
||||
<text x="370" y="254.5" class="c sub b">阻塞</text>
|
||||
<rect x="590" y="132" width="100" height="36" rx="6" fill="#EAE9E7" stroke="#BFBEBA"/>
|
||||
<text x="640" y="154.5" class="c sub b">终止</text>
|
||||
<line x1="142" y1="150" x2="218" y2="150" class="arrow "/>
|
||||
<text x="180" y="142" class="c sub">创建完成</text>
|
||||
<path d="M322,140 L418,140" class="arrow"/>
|
||||
<text x="370" y="132" class="c sub">被调度</text>
|
||||
<path d="M418,162 L322,162" class="arrow"/>
|
||||
<text x="370" y="180" class="c sub">时间片用完</text>
|
||||
<line x1="522" y1="150" x2="588" y2="150" class="arrow "/>
|
||||
<text x="555" y="142" class="c sub">结束</text>
|
||||
<path d="M470,170 C470,230 440,250 422,250" class="arrow"/>
|
||||
<text x="480" y="220" class="sub">等待 I/O 或事件</text>
|
||||
<path d="M318,250 C290,250 270,220 270,172" class="arrow"/>
|
||||
<text x="260" y="222" class="sub e">I/O 完成</text>
|
||||
<text x="30" y="288" class="sub">只有就绪和运行可以相互转换;阻塞的进程即使 CPU 空闲也不能运行,要先回到就绪队列。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
@@ -0,0 +1,67 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="740" height="300" viewBox="0 0 740 300">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="370" y="28" class="title">浏览器进程中的多个线程</text>
|
||||
<rect x="30" y="46" width="680" height="210" rx="8" class="frame"/>
|
||||
<text x="40" y="64" class="b">浏览器进程</text>
|
||||
<text x="50" y="82" class="sub b" style="fill:#444">所有线程共享:</text>
|
||||
<rect x="150" y="66" width="80" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="190" y="83" class="c sub" style="fill:#444">代码</text>
|
||||
<rect x="238" y="66" width="100" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="288" y="83" class="c sub" style="fill:#444">全局数据</text>
|
||||
<rect x="346" y="66" width="70" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="381" y="83" class="c sub" style="fill:#444">堆</text>
|
||||
<rect x="424" y="66" width="160" height="26" rx="3" fill="#C6E4FB" stroke="#7FB2D6" stroke-width="1"/>
|
||||
<text x="504" y="83" class="c sub" style="fill:#444">打开的文件、网络连接</text>
|
||||
<rect x="60" y="116" width="190" height="120" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="155" y="138" class="c sub b" style="fill:#444">网络请求线程</text>
|
||||
<rect x="75" y="150" width="160" height="24" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="155" y="166" class="c sub" style="fill:#444">自己的栈</text>
|
||||
<rect x="75" y="180" width="160" height="24" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="155" y="196" class="c sub" style="fill:#444">寄存器、程序计数器</text>
|
||||
<text x="155" y="224" class="c sub">独立调度</text>
|
||||
<rect x="280" y="116" width="190" height="120" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="375" y="138" class="c sub b" style="fill:#444">事件响应线程</text>
|
||||
<rect x="295" y="150" width="160" height="24" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="375" y="166" class="c sub" style="fill:#444">自己的栈</text>
|
||||
<rect x="295" y="180" width="160" height="24" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="375" y="196" class="c sub" style="fill:#444">寄存器、程序计数器</text>
|
||||
<text x="375" y="224" class="c sub">独立调度</text>
|
||||
<rect x="500" y="116" width="190" height="120" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="595" y="138" class="c sub b" style="fill:#444">渲染线程</text>
|
||||
<rect x="515" y="150" width="160" height="24" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="595" y="166" class="c sub" style="fill:#444">自己的栈</text>
|
||||
<rect x="515" y="180" width="160" height="24" rx="3" fill="#FFFFFF" stroke="#BBBBBB" stroke-width="1"/>
|
||||
<text x="595" y="196" class="c sub" style="fill:#444">寄存器、程序计数器</text>
|
||||
<text x="595" y="224" class="c sub">独立调度</text>
|
||||
<text x="30" y="284" class="sub">线程共享进程的内存,可以直接读写同一个变量通信;每个线程只有自己的栈和寄存器,所以创建和切换的开销比进程小。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.5 KiB |