From 04feb0988d61d21c8e2cf109d7c5315df7e45f1b Mon Sep 17 00:00:00 2001 From: ZZIcarus <2450606426@qq.com> Date: Mon, 30 Sep 2024 11:21:42 +0800 Subject: [PATCH] vault backup: 2024-09-30 11:21:42 --- docs/CS/CA/Pipelining.md | 20 ++ docs/CS/CA/index.md | 6 +- docs/CS/CN/Application Layer.md | 0 docs/CS/CN/Ch1_.md | 28 -- docs/CS/CN/Data Link Layer.md | 0 docs/CS/CN/Overview.md | 109 +++++++ docs/CS/CN/Physical Layer.md | 78 +++++ docs/CS/CN/Transport Layer.md | 0 docs/CS/CN/cs144.md | 7 + docs/CS/CN/index.md | 2 +- "docs/CS/CN/\351\242\230\347\233\256.md" | 5 + docs/CS/Java/notes.md | 158 +++++++++- docs/CS/OS/Ch1_Overview.md | 98 ++++++ docs/CS/OS/Ch2_Process.md | 105 +++++++ docs/CS/{CA/Ch1.md => OS/Ch3_Threads.md} | 4 +- docs/CS/index.md | 8 +- .../CS/\346\261\207\347\274\226/ReadNotes.md" | 14 + ...26\344\270\216\346\216\245\345\217\243.md" | 37 +++ ...26\344\270\216\346\216\245\345\217\243.md" | 8 - docs/Socket Pragramming.md | 32 ++ docs/Tools/CMake.md | 296 +++++++++++++++++- docs/Tools/Conda.md | 60 ++++ docs/Tools/GNUMake.md | 30 +- docs/Tools/Git.md | 6 +- .../Unix Command\345\244\207\345\277\230.md" | 2 - "docs/Tools/Unix\345\221\275\344\273\244.md" | 12 + docs/Tools/gcc & gdb.md | 24 ++ docs/Tools/gdb.md | 16 + docs/Tools/index.md | 5 +- ...31\350\241\250\350\276\276\345\274\217.md" | 3 +- docs/_templates/_read.md | 9 + mkdocs.yml | 15 + 32 files changed, 1123 insertions(+), 74 deletions(-) create mode 100644 docs/CS/CA/Pipelining.md create mode 100644 docs/CS/CN/Application Layer.md delete mode 100644 docs/CS/CN/Ch1_.md create mode 100644 docs/CS/CN/Data Link Layer.md create mode 100644 docs/CS/CN/Overview.md create mode 100644 docs/CS/CN/Physical Layer.md create mode 100644 docs/CS/CN/Transport Layer.md create mode 100644 docs/CS/CN/cs144.md create mode 100644 "docs/CS/CN/\351\242\230\347\233\256.md" create mode 100644 docs/CS/OS/Ch2_Process.md rename docs/CS/{CA/Ch1.md => OS/Ch3_Threads.md} (80%) create mode 100644 "docs/CS/\346\261\207\347\274\226/ReadNotes.md" create mode 100644 "docs/CS/\346\261\207\347\274\226/\346\261\207\347\274\226\344\270\216\346\216\245\345\217\243.md" delete mode 100644 "docs/CS/\346\261\207\347\274\226\344\270\216\346\216\245\345\217\243.md" create mode 100644 docs/Socket Pragramming.md delete mode 100644 "docs/Tools/Unix Command\345\244\207\345\277\230.md" create mode 100644 "docs/Tools/Unix\345\221\275\344\273\244.md" create mode 100644 docs/Tools/gcc & gdb.md create mode 100644 docs/Tools/gdb.md create mode 100644 docs/_templates/_read.md diff --git a/docs/CS/CA/Pipelining.md b/docs/CS/CA/Pipelining.md new file mode 100644 index 00000000..93d35317 --- /dev/null +++ b/docs/CS/CA/Pipelining.md @@ -0,0 +1,20 @@ +--- +tags: + - doing + - class/CA +statistics: true +title: NOTE +author: zzicarus +date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +--- +# Pipelining +## Hazard +**Structural Hazard** +- Double bump + - WRITE-then-READ +**Control Hazard** +- 延时槽 branch delay slots +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409241534052.png) +## FP units +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409241540466.png) diff --git a/docs/CS/CA/index.md b/docs/CS/CA/index.md index c1f46a04..4eef8d7b 100644 --- a/docs/CS/CA/index.md +++ b/docs/CS/CA/index.md @@ -8,7 +8,11 @@ Publish: draft author: zzicarus --- >[!abstract] 概述 -> +>>[!note] 分数构成 +>>![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409161011074.png) + + + >[!note] 个人感受 diff --git a/docs/CS/CN/Application Layer.md b/docs/CS/CN/Application Layer.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/CS/CN/Ch1_.md b/docs/CS/CN/Ch1_.md deleted file mode 100644 index a7f886b1..00000000 --- a/docs/CS/CN/Ch1_.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -tags: - - doing - - CN -statistics: true -title: NOTE -author: zzicarus -date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> -update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> ---- - -# Overview -## 实验部分 | 了解一些术语和基本协议 ->[!note] Terms ->- ISP(Internet Service Provider)因特网服务提供商 ->- router 路由器 ->- message -> - packet 将较长的 message 进行分组后的结果 ->- packet switch 分组交换机 ->- - ->[!note] 传输层协议 -TCP 面向连接的 -UDP -MAC 唯一的,基于网卡的 - ->[!info] Four Internet Model ->![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409121558575.png) diff --git a/docs/CS/CN/Data Link Layer.md b/docs/CS/CN/Data Link Layer.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/CS/CN/Overview.md b/docs/CS/CN/Overview.md new file mode 100644 index 00000000..2f403944 --- /dev/null +++ b/docs/CS/CN/Overview.md @@ -0,0 +1,109 @@ +--- +tags: + - doing + - CN +statistics: true +title: NOTE +author: zzicarus +date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +--- + +# Overview +## 实验部分 | 了解一些术语和基本协议 +>[!note] Terms +>- ISP(Internet Service Provider)因特网服务提供商。端系统通过 ISP 连接到网络 +>- host/end system 主机/端系统 +>- message +> - packet 将较长的 message 进行分组后的结果。当一台端系统要向另一台端系统发送数据时,发送端系统将数据分段,并为每段加上首部字节。 +>- communication Link 通信链路 +>- packet switch 分组交换机 +> - router 路由器 +> - link-layer switch 链路层交换机 +>- socket interface 套接字接口是数据发送端需要遵循的一种规则,这样数据才能正常发送 +>- + +>[!note] 传输层协议 +TCP 面向连接的 +UDP +MAC 唯一的,基于网卡的 + +>[!info] Four Internet Model +>![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409121558575.png) + +## 交换方式 +`Router` 对收到的 packet 进行存储转发实现分组交换 +- 电路交换 + 有线电话网络。 + - 连接建立 —— 数据传送 —— 连接释放 + - 缺点:中间节点无法发现并纠正错误;建立连接时间长 +- 报文(message)交换 ——使用存储转发技术 + 将 data 和其他数据封装 +- 分组交换 —— 在报文交换的基础上,对较长的 message 进行划分,在头部加上数据段形成新的 packet + - 可以进行流水线化处理 + +## 计算机网络的分类 +## 性能指标 +- **Speed**:连接到网络上的节点在数字信道上传送数据的速率,又称之为数据传输速率、比特率,单位 b/s 、bit/s 、bps +- **Bandwidth 带宽**:最高数据传输速率 +- **Throughput 吞吐量**:单位时间通过某个网络的实际数据量 +- **Delay 时间延迟**: 发送延迟 + 传播延迟 + 处理延迟 + 排队延迟 + - 发送时延又称为传输时延,一个分组传输的的时间 + - 传播时延是从某个 router 到另一个 router,是两台路由器之间距离的函数 +- **时延带宽积** = 传播时延 * 信道带宽,是发送的第一个 bit 到达终点时,发送端发出的 **bit 数** +- **Round-Trip Time | RTT 往返时延**: +- +>[!caution] 注意审题 +>看看清楚 bits 还是 byte,1 B = 8 bits + +## OSI 模型 & TCP/IP 模型 +![image.png](http://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409242000269.png) +### OSI +![image.png](http://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409242003204.png) + +- Service +- Interface +- Protocol +**各层级的作用** +- Physical Layer 物理层并不是物理介质,不包括电缆线等这些介质。规定了一些电路接口、信号 +- Network Layer + 传输单位为 ``。 +- Data Link Layer + 将来自网络层的 IP 分组封装成 **frame**,可靠地传输到相邻结点的网络层。可以将强物理层传输原始比特流的功能,将物理层可能出错的错误进行修正 + > The data link layer operates between two directly connected nodes and does not provide end-to-end communication。 + + + + +IP Service +**simple service** +- Datagram +- Unreliable +- Best Effort +- Connectionless +**features** +- End-to-end + +- 阻止 packets 永远 loop + - TTL +- Fragment packet +- Header to checksum +- 可拓展,增加新的 options 到 header + +**IPV4** +![image.png](http://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409241207369.png) + +- Version: IPV 4/6 +- Total Packer Length :Header and data +- Type Of service: how important +- Packet ID +- Flags +- Fragment Offset +- Protocol ID:说明 data 是哪种类型,将 data 交给相应的 code 进行处理。( == 6 ) +- TTL + +采用 three-way handshake 方法 + +**TCP** + +Forwarding table \ No newline at end of file diff --git a/docs/CS/CN/Physical Layer.md b/docs/CS/CN/Physical Layer.md new file mode 100644 index 00000000..ce8551c1 --- /dev/null +++ b/docs/CS/CN/Physical Layer.md @@ -0,0 +1,78 @@ +--- +tags: + - doing +statistics: true +title: NOTE +author: zzicarus +date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +--- +# Physical Layer + +- 速率 + - **码元传输速率/波特率** :单位时间数字通信系统传输的码元数 Baud + - **信息传输速率/比特率 max data rate** : 单位时间内数字通信系统传输的二进制码元数 b/s +- 带宽 + - 在模拟信号系统,某个信道传输信号的频率范围 Hz + - 计算机网络,网络的通信线路传输数据的能力——**最高数据率**,b/s +- Maximum Data Rate + - **Nyquist’s theorem** 在理想低通(无噪声、宽带有限)的条件下,避免码间串行 + - 极限码元传输速率为 2W Baud (W 为 channel 的频率带宽) + - 极限数据传输速率 = $2Wlog_2V$ (V 为每个码元的离散电平数目——多少种不同的码元) + - **Shannon’s formula** for capacity of **a noisy channel** + - Max data rate = $Wlog_2{(1+\frac{S}{N})}$ S 传输信号的平均功率,N 高斯噪声功率,信噪比 = S/N = $10log_{10}S/N$ dB +>[!note] +> +- 编码:数据 -> 数字信号 + - **归零编码 Return to Zero (RZ)**: 每个时钟周期均跳变到低电平(归零) + - **非归零编码 Non-Return to Zero (NRZ)** + - **反向非归零编码 NRZ Insert (NRZI)**:信号翻转代表 1,不翻转代表 0 + - **曼彻斯特编码 Manchester**: 将码元分割成两个相等的间隔,下跳表示 1,上跳表示 0. 电平跳变既是时钟信号用于同步,又是数据信号 + - 以太网使用 + - **差分曼彻斯特编码**:电平跳变仅仅表示时钟信号,码元开始处无跳变为 0 有则为 1 +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409261002264.png) + +- 调制:数据 -> 模拟信号 module + - FM 应用广泛 + - PM 改变载波的香味来表示 1/0,用相位 $0/pai$ 表示——绝对调相 + - QAM 正交幅度调制 :在频率相同的条件下,结合 AM、PM +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409261020490.png) +- 多路复用 multiplexing + - + +## Guided Transmission Media +- Persistent storage +- Twisted pairs 双绞线 +- Coaxial cable 同轴电缆 +- Power lines +- Fiber optics 光纤 + - Essentially infinite bandwidth + - + +## Wireless + +## From Waveforms to bits +- 傅里叶变换 + ![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409251023470.png) + +- Bandwidth-limited signals +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409260926012.png) +## Multiplexing +### Frequency Division Multiplexing +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409261034571.png) +- 同时不同频 +### Time Division Multiplexing +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409261034127.png) +- 按时间分时 +### Code Division Multiplexing +- 码分,更加灵活可以灵活调整带宽的分配 +- 同频又同时,同时发出但存在规律可以反解码 +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409261044456.png) +- 0 silence,-1 发送 0,1 发送 1 +### Wavelength Division Multiplexing +- 不同光的频率不同,本质上是频分 +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409261046301.png) +## 设备 | 中继器 +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409261055974.png) +- 上面的方式 A/D 转换次数多,信噪比低,传输速率低 +- Trunk \ No newline at end of file diff --git a/docs/CS/CN/Transport Layer.md b/docs/CS/CN/Transport Layer.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/CS/CN/cs144.md b/docs/CS/CN/cs144.md new file mode 100644 index 00000000..3e794857 --- /dev/null +++ b/docs/CS/CN/cs144.md @@ -0,0 +1,7 @@ +Packet Switching +只需要考虑高速传递信息 +**Flow** +同一端到端的 datagrams 的集合 +- Statical Multiplexing + - 允许 flows 使用所有的 link capacity + - 允许 flows share link capacity diff --git a/docs/CS/CN/index.md b/docs/CS/CN/index.md index 5111a1fd..d7964c85 100644 --- a/docs/CS/CN/index.md +++ b/docs/CS/CN/index.md @@ -16,6 +16,6 @@ author: zzicarus >[!todo] Todo >- [ ] todolist -- [[../CA/Ch1|Overview]] +- [[../CA/Pipelining|Overview]] - [[Network Layer]] - \ No newline at end of file diff --git "a/docs/CS/CN/\351\242\230\347\233\256.md" "b/docs/CS/CN/\351\242\230\347\233\256.md" new file mode 100644 index 00000000..33f24d96 --- /dev/null +++ "b/docs/CS/CN/\351\242\230\347\233\256.md" @@ -0,0 +1,5 @@ +# 题目 +## Overview +**Q 1.** A collection of five routers is to be connected in a point-to-point subnet. Between each pair of routers, the designers may put a high-speed line, a medium-speed line, a low-speed line, or no line. If it takes 100 ms of computer time to generate and inspect each topology, how long will it take to inspect all of them? (give your answer as xxx.xx) + +> $C_{5}^{2}=10$ 种拓朴链接方式,每一种都有四种连线方式,共计 $4^{10}$ 种选择方式,104857.60 sec \ No newline at end of file diff --git a/docs/CS/Java/notes.md b/docs/CS/Java/notes.md index 40170ab2..e2c64a1b 100644 --- a/docs/CS/Java/notes.md +++ b/docs/CS/Java/notes.md @@ -8,8 +8,164 @@ author: zzicarus date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> --- + +>[!todo] +>- [ ] 垃圾回收机制 +>- [ ] 内存分布 +>- [ ] 类 +> - [ ] 继承 +> # Java +>[!tip] +>- 用 `jshell` 可以使用与 python 类似的交互 + +>[!info] 概念 +>- SDK +>- JDK ## overview +- Compiled Language - All objects should be constructed in runtime and be stored in heap. - Every class in Java is a descendant of one class: Object -- \ No newline at end of file +- Java 中的输入输出,Scanner 容易超时 +```Java +//import java.util.*; +import java.util.Scanner; +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + System.out.println(a); + } +} +``` +- Java 中的保留字 +- Identifier +>[!note] 和 C++ 不同的语言特性 +>- Java 中的常量使用关键字 `final` 而不是 `const`. `final int a = 5;` +>- Java 中类型推导关键字为 `var`. `var s = new StringBuffer();` +>- Java 的 reference 更像是 C++中的指针,不可计算. 任何对象变量都是指针 +> - +> - 对象变量的赋值 +> >[!example] +> >将这里理解为类似指针,是操作权指向的赋予,不会像 C++ 一样做赋值 +> > ```Java +> > var a = new A(10); +> > var b = new A(20); +> > System.out.printf("%d %d\n", a.i, b.i); +> > a = b; +> > b.i = -20; +> > System.out.printf("%d %d\n", a.i, b.i); +> > ``` +>- Auto Memory Management -- 单根结构 +>- index check +> - Primitive 可以存放在栈,对象全部都放在堆(heap 只能通过 `new` 获得) +> +>>[!note] Dynamic +>>- Java 中的一个文件只能含有一个 `public` 类,其名称与文件名称相同 + +>[!important] Java 的运行 +>![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409191528128.png) +### 内存布局 +## String API +- 所有字符类型都是 unicode,就像下面的中文也会是一个字节 +```Java title="对长度的判断" +String a = "hello你好"; // len = 7 +String b = "hello"; // len = 5 +``` +- String 为不可变类型。 +### Methods +**得到属性** +- `s.length () ` +- `s.charAt (int index) ` +**切片** +- `s.substring (int , int )` +- +**比较** +- `s.compareTo ()` +- `s.equals ()` +- `s.equalsIgnoreCase ()` +- `Boolean startsWith (String str)` +- `Boolean endsWith (String str)` +**变换** +- `String trim ()` 删除前导、后导空格 +- `String replace (char c 1, char c 2)` +- `public String replaceAll(String regex, String replacement)` 可使用正则表达式进行替换。[[../../Tools/正则表达式|正则表达式]] +**与其他的值相互转化** +```JAVA +String piStr = "3.14159"; +Float pi = Float.ValueOf (piStr); +Float pi 2 = Float.ParseFLOAT (piStr); +``` +## Basic +**参数传递** +- Passing value +- 对象传递也是类似指针,无法阻止函数内部对对象的改变 +**Relation** +- 整型的 wrapper 在[-128,127]之间是一个固定的对象 +```Java +Integer n1 = new Integer(47); +Integer n2 = new Integer(47); +System.out.println(n1 == n2);  // false + +Integer n3 = 47;   +Integer n4 = 47; +System.out.println(n3 == n4);  // true +``` +### Package + +### Class +>[!note] +>- 类在内存中也是一个对象属于 Class +>- Java 会对 new 的对象的内存清空为 0 +>- 定义初始化,在构造函数之前,初始化顺序与在 class 中定义的顺序相关 +- 代理构造 + ```java +public Rectangle(int width, int length) { + this.width = width; + this.length = length; +} +public Rectangle() { + this(0, 0); +} + ``` +```mermaid +graph LR +1[Load 调用static函数] --> 2[定义初始化] --> 3[调用构造函数] + +``` +```Java +Flower(String s, int petals) { +        this(petals); +        this.s = s; // Another use of "this" +        System.out.println("String & int args"); +    } +``` +- 静态 + + +## 练习题 +### Week 1 + +### Week 2 +--- +>[!question] +>**Q 1** +>About access control in Java, which statement below is correct? +> +>A. A member without any access modifier is default to private +> +>B. A member without any access modifier is default to public +> +>C. A member without any access modifier is default to protected +> +>**D. Classes in the same package can access members without any access modifier.** + +>[!note] +>Java 中的访问权限是 public、protected、default 和 private。其中 default 具有包访问权 + +--- +>[!question] +>**Q 2** +>![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409201632308.png) + +### Week 3 diff --git a/docs/CS/OS/Ch1_Overview.md b/docs/CS/OS/Ch1_Overview.md index 6825dd3a..47d20aef 100644 --- a/docs/CS/OS/Ch1_Overview.md +++ b/docs/CS/OS/Ch1_Overview.md @@ -1,6 +1,7 @@ --- tags: - doing + - class/OS statistics: true title: NOTE author: zzicarus @@ -8,3 +9,100 @@ date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> --- # overview +>[!note] 什么是一个操作系统? +>一个不断运行着的、控制硬件的软件程序 +>**职能** +>- Resource Allocator +>为上层的 App 分配底层资源 +>- Control Program +>控制程序的运行,防止错误的发生 +> +## Architecture +- Single Processor System +- Multiprocessor System + - 单核 + 多个 Processor 拥有各自的 local cache 但共享物理资源. 每一对 CPU 都执行所有的任务 + ![](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409181433920.png) + - 多核 + 多核的优势在于耗能更低,一个芯片中数据交互更方便 + ![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409181458604.png) + - NUMA + +## Operation +```mermaid +graph LR +1[interrupt] +1-->2[hardware] +1-->3[trap/exception] +3-->4[error] +3-->5[system call] +``` +### Multiprogram & Multitasks +前者偏向于改进系统效率方面,后者偏向于改进用户体验 +**Multiprogram** 增强了 CPU 的利用效能 +- A subset of total jobs in system is kept in memory +- + +**Multitasks** | Time sharing +>在同一时间内让多个任务(或进程)共享系统资源并同时运行的技术。尽管在单核CPU上,实际上每次只能执行一个任务,操作系统通过快速切换任务,让用户感觉多个任务在同时进行。 +- Response Time 比较短,有利于交互 +- 把 CPU 分为不同的 Time Slides,不断切换不同的进程 +### Dual Modes +存在一个 Mode bit 来控制状态,0(内核态)1(用户模式) +- User Mode 发出 system call +- Privilege | Kernel | system | supervisor Mode +存在风险的指令为 `Privileged Instructions`,只能由内核模式执行。**中断只能运行在 kernel mode** +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409181501574.png) + +### Timer +> 一般包含一个 clock 和一个 counter,每次 clock tick 都会使 counter--,counter 等于 0 触发中断。 +> 在进入用户模式之前(before scheduling process),都会设置一个 Timer,防止陷入无限循环。 + +## Resource Management +操作系统为进程分配资源,如 CPU、 Memory、 Input Data 等等 +### Process Management +>[!note] 什么是进程? +>一个单独的程序并不是一个进程,一个程序是静态的,是 passive entity。而进程要求是一个运行中的程序,active entity。 +> +>进程具有 Isolation 的特点,一个进程爆了并不会影响另外一个 + +>[!tip] 进程和线程 +>|特性|进程|线程| +>|---|---|---| +>|内存空间|独立分配|共享同一进程的内存空间| +>|资源占用|占用较多资源|占用资源少,切换成本低| +>|通信方式|需要通过IPC机制|共享内存,通信简单| +>|创建开销|创建和切换开销较大|创建和切换开销较小| +>|崩溃影响|一个进程崩溃不会影响其他进程|一个线程崩溃可能影响进程内其他线程| + +- 一个进程下可以有多个线程 +- 每一个线程都会有一个 Program Counter 指向下一个要执行的指令 +### Memory Management + +## Operating System Structures +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409191453374.png) +### System Call + +https://note.hobbitqia.cc/OS/chap01/#system-calls +### Operating System +![image.png](http://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409251424254.png) + +## Linker And Loader +![image.png](http://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409251715414.png) +- 详细:[HabbitQia学长的Notes](https://note.hobbitqia.cc/OS/chap01/#running-a-binary-dynamically-linked) +## VM +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409251451984.png) +## System boot +硬件如何确定操作系统的位置呢?这需要有一段代码可以定位内核的位置并把它放到 memory 中运行。这段代码就被称之为 **bootstrap program / bootstrap loader**. 通过加载内核来启动计算机的过程称之为 **booting** the system. + +**Process** +1. **bootstrap program or boot loader** locates the kernel. 定位内核 +2. The kernel is loaded into memory and started. 装载内核 +3. The kernel initializes hardware. 初始化硬件 +4. The root file system is mounted. 挂载根文件系统 +`mount`: 将一个文件系统和一个存储设备关联起来 +>[!quote] What is a `rootfs `? +>**The root filesystem is at the top of the hierarchical file tree** (also known as ‘/’). The Linux kernel directly mounts rootfs through the configuration argument ‘_root=_‘. The root filesystem also has mount points where we can mount other filesystems as well in order to connect them to this filesystem hierarchy. It has a number of directories containing files critical for booting the system and system operations. +>相较于其他文件系统,rootfs 的特殊之处就在于它是第一个被挂载的文件系统,且其被挂载之后,将启动一些默认的初始化程序。 +>比如,在命令 `` + diff --git a/docs/CS/OS/Ch2_Process.md b/docs/CS/OS/Ch2_Process.md new file mode 100644 index 00000000..f80c97b3 --- /dev/null +++ b/docs/CS/OS/Ch2_Process.md @@ -0,0 +1,105 @@ +--- +tags: + - doing + - class/OS +statistics: true +title: NOTE +author: zzicarus +date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +--- +## Concept +A `process` is one program being executing. (`job` 是历史遗留的称呼) + +>[!note] 内存布局 +>- Text 运行的代码 +>- Data 全局变量、静态变量 +>- heap 运行时动态申请 +>- stack 调用函数的临时变量 +> +>![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409281535558.png) +>>[!note] 一个 C 程序中各部分的内存布局 +>![](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409251532666.png) +>>使用 `size ` 命令查看, +>> ```c +> > text data bss dec hex filename + >1382 600 8 1990 7c6 test +> >``` +### State +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409251520016.png) +- `Scheduler dispatch ` : OS 进行 CPU 调度 +### Process Control Block | PCB +上面提到单个进程在 memory 中的内存布局以及 state 的转换,但我们的操作系统同时会运行多个进程,这些进程不断地切换,所以我们需要 PCB 来保存一些管理资源的必要信息。 +- PCB 相关的维护代码在 kernel 部分,在中断时调用更新 PCB 的值 +**PCB 的一般结构** +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409251548836.png) + +>[!note] 两个进程的示意图 +>通过 PCB 的切换来切换进程 +>![image.png](http://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409251549111.png) + +## Process Scheduling +> In general, most processes can be described as either I/O bound or CPU bound. 按照花费时间的多寡分类 +> An **I/O-bound process** is one that spends more of its time doing I/O than it spends doing computations. +> A **CPU-bound process**, in contrast, generates I/O requests infrequently, using more of its time doing computations. +### Scheduling Queues +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409281624763.png) + +- Job queue – set of **all processes** in the system +- Ready queue – set of all processes residing in main memory, ready and waiting to execute +- Device queues – set of processes waiting for an I/O device +- I/O waiting queue +- ...... +**运行示意图** +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409281618875.png) + +### Process Scheduler +- **Long-term scheduler** (or **job scheduler**) – selects which processes should be brought into memory (the ready queue) 选择哪一个程序进行运行 + - 控制 degree of multiprogramming +- **Short-term scheduler** (or **CPU scheduler**) – selects which process should be executed next and allocates CPU +- **Medium term** 进行 **swapping**,可以将一个 process 从内存移动到 disk,降低 multiprogram 的程度,之后再存回来 +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409281627397.png) +## Process Operation +> Linux 可以使用 `ps/pstree` 命令查看当前进程 +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409281633165.png) +- 不同 process 之间使用 pid 区分 +- Systemd pid = 1 +### Creation +![image.png](https://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202409281709506.png) + +- `Fork` 创建一个新的进程,对于新创建的子进程,其返回值为 0 否则为 pid 值 + >[!note] From Linux `fork` Manual + > The child process is an exact duplicate of the parent process except for the following points: + >- does not inherit its parent's memory locks + > + >**Return value** + >On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is returned in the parent, no child process is created, and err no is set appropriately. +- `Exec` 载入新的二进制程序,顶替之前的镜像 +- `waie` 父进程阻塞,等待子进程 +**Resource sharing 的分类** +- 子进程和父进程共享 +- 子进程的资源严格限制在父进程的子集中 +- No resource sharing +**父进程在创建子进程之后** +- 阻塞,等待 child process +- 并行执行 +**子进程** +- 要么是父进程的 duplicate +- 要么 load 另一个程序 +### Termination +**Exit** : A process terminates when it finishes executing its final statement and asks the operating system to delete it by using the ` exit() ` system call. 运行结束 +- 为 waiting 中的父进程返回 status value +- Deallocated 所有分配的资源 +**Abort** : Parent may terminate execution of children processes +- Child has exceeded allocated resources +- Task assigned to child is no longer required +- Parent 存在 + - **cascading termination** :部分操作系统不允许没有父进程的子进程存在,在父进程中止时会级联中断子进程 + - In some other operating systems, the child gets orphaned – and its parent becomes the “init” process (PID=1). 父进程不调用 wait 的情况下,子进程成为“孤儿”,这时部分操作系统会把父进程设置为 systemd,其周期性调用 wait 函数 + +>[!note] +>所有中断的进程都会变成 **zombie** process,只有在父进程调用 wait 之后,进程相关的 process table 的内容才会被释放 +## Interprocess Communication +- Shared Memory +- Message Passing + - 需要 copy 多次内存/Buffer diff --git a/docs/CS/CA/Ch1.md b/docs/CS/OS/Ch3_Threads.md similarity index 80% rename from docs/CS/CA/Ch1.md rename to docs/CS/OS/Ch3_Threads.md index 39a57af7..6db73c97 100644 --- a/docs/CS/CA/Ch1.md +++ b/docs/CS/OS/Ch3_Threads.md @@ -1,10 +1,12 @@ --- tags: - doing - - class/CA + - class/OS statistics: true title: NOTE author: zzicarus date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> --- +# Thread & Concurrency +## \ No newline at end of file diff --git a/docs/CS/index.md b/docs/CS/index.md index f7210173..a29ada28 100644 --- a/docs/CS/index.md +++ b/docs/CS/index.md @@ -4,16 +4,17 @@ > ## 仓库收集 -- [求是潮](https://github.com/QSCTech/zju-icicles) +- [求是潮](https://github.com/QSCTech/zju-icicles)比较老旧,但很全面 - [ZJU-CKCMix-CS-Course-Material](https://github.com/zyxNova/ZJU-CKCMix-CS-Course-Material/tree/master) - [CourseNoteOfZJUSE](https://github.com/Zhang-Each/CourseNoteOfZJUSE) - [ZJU-CS](https://github.com/2811668688/ZJU-CS) 含有 CS 比较全的课程资料 - [Latex笔记](https://github.com/Tian42chen/Transcription-Malfunctioned) ## 笔记收集 - [修佬](https://note.isshikih.top/) +- [HobbitQia](https://note.hobbitqia.cc/) - [咸鱼暄](https://xuan-insr.github.io/) - [小角龙](https://zhang-each.github.io/My-CS-Notebook/) -- +- [鹤翔万里](https://note.tonycrane.cc/) ## 专业主修课 ### 离散数学/DM ### 数字逻辑 @@ -41,7 +42,7 @@ > > **书目** > - 王道 -> - [Top and down](https://github.com/ece-cohort/Computer-Networking-A-Top-Down-Approach-7th-Edition) +> - [Top and down](https://github.com/ece-cohort/Computer-Networking-A-Top-Down-Approach-7th-Edition) 计算机网络:自顶向下方法 ### 操作系统 | OS > [!info] @@ -65,7 +66,6 @@ [[Java/index]] ### 汇编与接口 [[汇编与接口]] - - [22-23 回忆卷](https://www.cc98.org/topic/5510882) - [23-24 回忆卷](https://www.cc98.org/topic/5804583) - \ No newline at end of file diff --git "a/docs/CS/\346\261\207\347\274\226/ReadNotes.md" "b/docs/CS/\346\261\207\347\274\226/ReadNotes.md" new file mode 100644 index 00000000..b40bfeca --- /dev/null +++ "b/docs/CS/\346\261\207\347\274\226/ReadNotes.md" @@ -0,0 +1,14 @@ +--- +tags: + - doing +Statistics: true +Title: Reading +Author: zzicarus +date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +--- +- 总线 + - 数据总线 + - 控制总线 + - 地址总线 +在 PC 中,CPU 通过总线与其他器件连接/进行控制(通过拓展卡槽),并不能直接控制 \ No newline at end of file diff --git "a/docs/CS/\346\261\207\347\274\226/\346\261\207\347\274\226\344\270\216\346\216\245\345\217\243.md" "b/docs/CS/\346\261\207\347\274\226/\346\261\207\347\274\226\344\270\216\346\216\245\345\217\243.md" new file mode 100644 index 00000000..d23ed049 --- /dev/null +++ "b/docs/CS/\346\261\207\347\274\226/\346\261\207\347\274\226\344\270\216\346\216\245\345\217\243.md" @@ -0,0 +1,37 @@ +--- +tags: + - doing +statistics: true +title: NOTE +publish: draft +author: zzicarus +Statistics: false +Title: Index +--- +>[!abstract] 概述 +>>[!note] 成绩组成 +>>- 实验 30% +>> - 探究实验两个 +>>- 考试 70% +> +>>[!summary] Topics +>>今年减少了 Interrupts 和 Arithmetic coprocessor 两大章 +>> - The microprocessor and its architecture (Chap. 1-2) +>> - Addressing modes (Chap. 3) +>> - Data movement instructions (Chap. 4) +>> - Arithmetic and logic instructions (Chap. 5) +>> - Program control instructions (Chap. 6) +>> - Using assembly language with c/c++ (Chap. 7) +>> - Basic I/O interface (Chap. 11) +>> - ~~Interrupts (Chap. 12)~~ +>> - ~~Arithmetic coprocessor and SIMD (chap. 14/++)~~ + +>[!note] 个人感受 + +>[!info] 资源 +>- Tools +> - [Compiler](https://www.godbolt.org/) +> - [Online x86 / x64 Assembler and Disassembler](https://defuse.ca/online-x86-assembler.htm#disassembly) + +>[!todo] Todo +>- [ ] todolist diff --git "a/docs/CS/\346\261\207\347\274\226\344\270\216\346\216\245\345\217\243.md" "b/docs/CS/\346\261\207\347\274\226\344\270\216\346\216\245\345\217\243.md" deleted file mode 100644 index 64c7b18a..00000000 --- "a/docs/CS/\346\261\207\347\274\226\344\270\216\346\216\245\345\217\243.md" +++ /dev/null @@ -1,8 +0,0 @@ ---- -tags: - - doing -statistics: true -title: NOTE -publish: draft -author: zzicarus ---- diff --git a/docs/Socket Pragramming.md b/docs/Socket Pragramming.md new file mode 100644 index 00000000..584029d1 --- /dev/null +++ b/docs/Socket Pragramming.md @@ -0,0 +1,32 @@ +**参考:** +- [微软官方文档 · Winsock 入门]([Winsock 入门 - Win32 apps | Microsoft Learn](https://learn.microsoft.com/zh-cn/windows/win32/winsock/getting-started-with-winsock)) +- [Youtube视频 · C++ Network Programming]([C++ Network Programming Part 1: Sockets (youtube.com)](https://www.youtube.com/watch?v=gntyAFoZp-E)) + +Server 的端口由 code 指定,client 由 OS 分配 +WinSocket 的操作是针对某个 socket 的 +Socket act as pipe +**Server** +- Bind + 将 Socket 和 IP 和 Port 进行绑定 +- Listening + +**Client** +- Bind + +- Connected + +## 服务器 +1. 初始化 Winsock。`WASStartup` +2. 创建套接字。 `socket` +3. 绑定套接字。`bind` +4. 侦听客户端的套接字。 `listen` +5. 接受来自客户端的连接。 `accept connect` +6. 接收和发送数据。 `recv send secvfrom sendto` +7. 断开连接。 `closesocket` + +## 客户端 +1. 初始化 Winsock。 +2. 创建套接字。 +3. 连接到该服务器。 +4. 发送和接收数据。 +5. 断开连接。 \ No newline at end of file diff --git a/docs/Tools/CMake.md b/docs/Tools/CMake.md index 2a45ceff..8237135c 100644 --- a/docs/Tools/CMake.md +++ b/docs/Tools/CMake.md @@ -5,6 +5,298 @@ tags: # CMake -!!! abstract "资源" - 官方教程 : https://cmake.org/cmake/help/latest/guide/tutorial/index.html +!!! Info "INFO" + - [官方教程](https://cmake.org/cmake/help/latest/guide/tutorial/) +![image-20240223212218052](http://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202402232122164.png) +> 1. CMake 中的对齐很重要!!! +> ![image-20240223212218052](http://zzh-pic-for-self.oss-cn-hangzhou.aliyuncs.com/img/202402232122164.png) +> 2. + +## Step 1 Starting Point + +==文件架构== + + ```text + step1/ + build/ + CMakeLists.txt + tutorial.cpp + ``` + +==演示== + +```CMAKE +# TODO 1: Set the minimum required version of CMake to be 3.10 +cmake_minimum_required(VERSION 3.10) + +# TODO 2: Create a project named Tutorial +project( + Tutorial + VERSION 1.0 + DESCRIPTION "这是一个演示项目" + HOMEPAGE_URL "https://cmake.org/cmake/help/latest/guide/tutorial/A%20Basic%20Starting%20Point.html#" + LANGUAGES CXX C +) + +# TODO 7: Set the project version number as 1.0 in the above project command +project(Tutorial VERSION 1.0) + +# TODO 6: Set the variable CMAKE_CXX_STANDARD to 11 +# and the variable CMAKE_CXX_STANDARD_REQUIRED to True +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# TODO 8: Use configure_file to configure and copy TutorialConfig.h.in to +# TutorialConfig.h +configure_file(TutorialConfig.h.in TutorialConfig.h) + +# TODO 3: Add an executable called Tutorial to the project +# Hint: Be sure to specify the source file as tutorial.cxx +add_executable(Tutorial tutorial.cxx) + +# TODO 9: Use target_include_directories to include ${PROJECT_BINARY_DIR} +target_include_directories(Tutorial PUBLIC + "${PROJECT_BINARY_DIR}" + ) +``` + +- `project` + Sets the name of the project, and stores it in the variable [`PROJECT_NAME`](https://cmake.org/cmake/help/latest/variable/PROJECT_NAME.html#variable:PROJECT_NAME). When called from the top-level `CMakeLists.txt` also stores the project name in the variable [`CMAKE_PROJECT_NAME`](https://cmake.org/cmake/help/latest/variable/CMAKE_PROJECT_NAME.html#variable:CMAKE_PROJECT_NAME). +- `configure_file` + ==TutorialConfig. H. In== + + ```c+ + // the configured options and settings for Tutorial + #define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@ + #define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@ + ``` + +- `target_include_directories` + +---- + +在 Run 之前,我们需要先构建 Build 目录 + +``` +> mkdir build +> cd build +> cmake -G"MinGW Makefiles" .. + +> cmake --build . +> ./Tutorial 4 +``` + +- Windows 下,CMake 默认使用微软的 MSVC 作为编译器,我想使用 MinGW 编译器,可以通过 `-G` 参数来进行指定,只有第一次构建项目时需要指定。 +- **``MinGW Makefiles``**是 CMake 所支持的一种生成器,它用于生成适用于 MinGW 工具链的 Makefiles。这些 Makefiles 包含了构建项目所需的指令,可以让你使用 MinGW 工具链来编译和构建你的项目。**当然,这一步也可以不这样指定** + +> < INTERFACE | PUBLIC | PRIVATE > +> +> **``PUBLIC``**: 当你使用**``target_link_libraries``**和**``target_include_directories``**命令将库链接到目标时,使用**``PUBLIC``**关键字表示,不仅会将库链接到目标本身,还会将库的依赖项传递给该目标的使用者。也就是说,如果一个目标链接到另一个目标,并且使用了**``PUBLIC``**关键字,那么链接到第一个目标的任何其他目标也会自动链接到第二个目标所链接的库。 +> +> **``PRIVATE``**: 使用**``PRIVATE``**关键字表示,链接库的目标将会链接到该库,但不会将该库的依赖项传递给链接到该目标的其他目标。 +> +> **``INTERFACE``**: 使用**``INTERFACE``**关键字表示,链接库的目标将不会链接到该库,但该库的依赖项会传递给链接到该目标的其他目标。 + +## Step 2 添加库 + +我们可以用一个或多个子目录来组织项目,而不是将所有源文件放在一个目录中。在这种情况下,我们将专门为我们的库创建一个子目录。在这里,我们可以添加一个新 `CMakeLists.txt` 文件和一个或多个源文件。在顶层 `CMakeLists.txt` 文件中,我们将使用 [`add_subdirectory()`](https://cmake.org/cmake/help/latest/command/add_subdirectory.html#command:add_subdirectory) 命令将子目录添加到构建中。 + +==文件架构== + + ```text + step2/ + build/ + MathFunctions/ + CMakeLists.txt + MathFunctions.cxx + MathFunctions.h + mysqrt.cxx + mysqrt.h + CMakeLists.txt + tutorial.cxx + TutorialConfig.h.in + ``` + +==演示== + +1. 底层的 MathFunctions + +```CMAKE +# TODO 14: Remove mysqrt.cxx from the list of sources +# TODO 1: Add a library called MathFunctions with sources MathFunctions.cxx +# and mysqrt.cxx +add_library(MathFunctions MathFunctions.cxx) +# TODO 7: Create a variable USE_MYMATH using option and set default to ON +option(USE_MYMATH "Use tutorial provided math implementation" ON) +# TODO 8: If USE_MYMATH is ON, use target_compile_definitions to pass +# USE_MYMATH as a precompiled definition to our source files +if (USE_MYMATH) + target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH") + # TODO 12: When USE_MYMATH is ON, add a library for SqrtLibrary with + # source mysqrt.cxx + add_library(SqrtLibrary STATIC + mysqrt.cxx + ) +# TODO 13: When USE_MYMATH is ON, link SqrtLibrary to the MathFunctions Library + target_link_libraries(MathFunctions PRIVATE SqrtLibrary) +endif() +``` + +2. 顶层的 + +```Cmake +cmake_minimum_required(VERSION 3.10) + +# set the project name and version +project(Tutorial VERSION 1.0) + +# specify the C++ standard +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# configure a header file to pass some of the CMake settings +# to the source code +configure_file(TutorialConfig.h.in TutorialConfig.h) + +# TODO 2: Use add_subdirectory() to add MathFunctions to this project +add_subdirectory(MathFunctions) +# add the executable +add_executable(Tutorial tutorial.cxx) + +# TODO 3: 将库链接到可执行文件 +target_link_libraries(Tutorial PUBLIC MathFunctions) +# TODO 4: Add MathFunctions to Tutorial's target_include_directories() +# Hint: ${PROJECT_SOURCE_DIR} is a path to the project source. AKA This folder! + +# add the binary tree to the search path for include files +# so that we will find TutorialConfig.h +target_include_directories(Tutorial PUBLIC + "${PROJECT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/MathFunctions" + ) +``` + +- `add_library` + 用于定义一个库,可以结合其他命令对库的属性进行配置。 + 1. 正常使用定义一个库 + 2. 创建一个只包含接口而没有实际源文件的库,它通常用于传递编译器标志、包含目录等信息给依赖项。[实例见下](#add_library_usage_2) + +- `target_link_libraries( ... ... ...)` + 命令用于将一个或多个库或目标链接到特定的目标上。这个命令可以用于指定目标需要链接的库,包括其他目标、库文件或链接器标志。 +- `add_subdirectory` + 将 ``MathFunctions`` 目录添加到项目中,这将调用 ``MathFunctions`` 目录中的 ``CMakeLists.txt`` 文件来构建库。 + +--- + +### 为库添加 Option + +允许开发人员选择自定义实现或内置标准实现。 + +- `target_compile_definitions` + 命令用于向特定目标添加编译定义。这些定义在编译目标时会传递给编译器。 + `target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")` 就是在编译 `MathFunctions` 的过程中,加入了 `USE_MYMATH` 的预定义变量;同时,Private 表示这个变量只是用于 `MathFunction` 中 + +- `option` + CMakeLists. Txt 文件中使用**``option``**命令定义的选项会被转化为 C/C++代码中的预处理器定义 + +> :question: How To Reset the option in the terminal ? +> +> :a: `cmake ../Step2 -DUSE_MYMATH=OFF` `-D` 选项用于在命令行中向 CMake 传递变量定义 +> 这一点有利于动态的配置项目 + +## Step 3 添加库的 Usage Requirments + +使用更加现代化的方式添加头文件依赖关系。 + +==文件架构== + + ```text +step3/ + build/ + MathFunctions/ + CMakeLists.txt + MathFunctions.cxx + MathFunctions.h + mysqrt.cxx + mysqrt.h + CMakeLists.txt + tutorial.cxx + TutorialConfig.h.in + ``` + +==演示== + +1. 底层的 MathFunctions + +```CMAKE +add_library(MathFunctions MathFunctions.cxx) + +# TODO 1: State that anybody linking to MathFunctions needs to include the +# current source directory, while MathFunctions itself doesn't. +# Hint: Use target_include_directories with the INTERFACE keyword +target_include_directories(MathFunctions + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} + ) +# should we use our own math functions +option(USE_MYMATH "Use tutorial provided math implementation" ON) + +if (USE_MYMATH) + target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH") + + # library that just does sqrt + add_library(SqrtLibrary STATIC + mysqrt.cxx + ) + + # TODO 6: Link SqrtLibrary to tutorial_compiler_flags + target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags) + target_link_libraries(MathFunctions PRIVATE SqrtLibrary) +endif() + +# TODO 7: Link MathFunctions to tutorial_compiler_flags +target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags) +``` + +2. 顶层的 line 11 add_library_usage_2 + +```Cmake +cmake_minimum_required(VERSION 3.10) + +# set the project name and version +project(Tutorial VERSION 1.0) + +# TODO 4: Replace the following code by: +# * Creating an interface library called tutorial_compiler_flags +# Hint: use add_library() with the INTERFACE signature +# * Add compiler feature cxx_std_11 to tutorial_compiler_flags +# Hint: Use target_compile_features() +add_library(tutorial_compiler_flags INTERFACE) +target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11) + +# configure a header file to pass some of the CMake settings +# to the source code +configure_file(TutorialConfig.h.in TutorialConfig.h) + +# TODO 2: Remove EXTRA_INCLUDES list +# add the MathFunctions library +add_subdirectory(MathFunctions) +# add the executable +add_executable(Tutorial tutorial.cxx) + +# TODO 5: Link Tutorial to tutorial_compiler_flags +target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags) + +# TODO 3: Remove use of EXTRA_INCLUDES +# add the binary tree to the search path for include files +# so that we will find TutorialConfig.h +target_include_directories(Tutorial PUBLIC + "${PROJECT_BINARY_DIR}" + ) +``` + +## Step 4 添加生成器表达式 + + + + diff --git a/docs/Tools/Conda.md b/docs/Tools/Conda.md index f1461e62..4e03103f 100644 --- a/docs/Tools/Conda.md +++ b/docs/Tools/Conda.md @@ -1,2 +1,62 @@ # Conda +!!! abstraction "Conda" + Conda是一个管理Python环境和版本的工具。 + +- [知乎](https://zhuanlan.zhihu.com/p/44398592) +- [官方](https://conda.io/projects/conda/en/latest/user-guide/getting-started.html) + +[CPU 算力](https://developer.nvidia.com/cuda-gpus) + +```python +conda create --name python=3.6 + +// 查看环境 +conda info --envs +conda info -e + +// 回到默认环境 +conda deactivate + +// 安装软件包 +# via environment activation +conda activate myenvironment +conda install matplotlib + +# via command line option +conda install --name myenvironment matplotlib +# 查看已经安装的packages +conda list +# 查看某个指定环境的已安装包 +conda list -n py35 +``` + +## 配置 Channels + +```shell +# 清华源 +https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ + +``` + +**查看当前channels信息** + +``` +conda config --show +conda config --get +``` + +**使用某个channels** + +```shell +conda install xxx -c channels +conda create xxx -c channels +``` + +**添加 channels** + +```sh +conda config --add channels +conda config --remove channels +``` + diff --git a/docs/Tools/GNUMake.md b/docs/Tools/GNUMake.md index ebc81623..7855715a 100644 --- a/docs/Tools/GNUMake.md +++ b/docs/Tools/GNUMake.md @@ -8,34 +8,24 @@ tags: > **资料:** > [makefile 介绍 — 跟我一起写 Makefile 1.0 文档](https://seisman.github.io/how-to-write-makefile/introduction.html) +> [上面文档的重制版本](https://write-makefile-with-me.elabtalk.com/articles) > **视频:** > 一个较简单的入门 [https://www.youtube.com/watch?v=E1_uuFWibuM&t=1152s](https://www.youtube.com/watch?v=E1_uuFWibuM&t=1152s) -!!! tip "TIPS" - - cc 是 C 编译器的命令。在一般的系统上(Unix/Linux),通常是一个指向 实际 C 编译器(gcc)的符号链接或别名 - - windows 下可以使用 gcc _.c -o _.o - +>[!tip] Tips +>- cc 是 C 编译器的命令。在一般的系统上(Unix/Linux),通常是一个指向实际 C 编译器(gcc)的符号链接或别名。一般可以直接把它定义为一个变量,更方便书写 +>- `make -j` 可以并行编译 `make -j($nproc)` 使用当前所有核 +>- 在某些命令前面可以加 `-` 表示不理会无法正确执行的步骤。例如,`-include ` 就会自动忽视无法找到路径的 `makefile ` ```c - ## 使用过程 // 指定文件 gcc your_source_file.c -o ../your_executable // 链接c++标准库 gcc source/pdShow.cpp pd.cpp -o source/pdShow -lstdc++ - ``` - - - - -​ - -- - ## 基本介绍 ```makefile @@ -52,9 +42,7 @@ target ... : prerequisites ... 生成该 target 所依赖的文件和/或 target。 **recipe** 该 target 要执行的命令(任意的 shell 命令)。 - - 第一个目标会作为默认目标 - ### 变量 - makefile 中的变量相当于 C 中的宏定义 @@ -63,19 +51,17 @@ target ... : prerequisites ... `usage` : `edit : $(objects)` ### Makefile 如何工作 - 1. make 会在当前目录下找名字叫“Makefile”或“makefile”的文件。 -2. 如果找到,它会找文件中的第一个目标文件(target),在上面的例子中,他会找到“edit”这个文件,并把这个文件作为最终的目标文件。 +2. 如果找到,它会找文件中的第一个目标文件(target),在上面的例子中,他会找到“edit”这个文件,并**把这个文件作为最终的目标文件**。 3. 如果 edit 文件不存在,或是 edit 所依赖的后面的 .o 文件的文件修改时间要比 edit 这个文件新,那么,他就会执行后面所定义的命令来生成 edit 这个文件。 4. 如果 edit 所依赖的 .o 文件也不存在,那么 make 会在当前文件中找目标为 .o 文件的依赖性,如果找到则再根据那一个规则生成 .o 文件。(这有点像一个堆栈的过程) 5. 当然,你的 C 文件和头文件是存在的啦,于是 make 会生成 .o 文件,然后再用 .o 文件生成 make 的终极任务,也就是可执行文件 edit 了。 -### windows - ## 书写规则 - 命令一定要以`tab`开头 - +>[!note] +>现在也可以使用其他方法来避免使用空格和 Tab 之间存在错误。 ### 通配符 `*` diff --git a/docs/Tools/Git.md b/docs/Tools/Git.md index e6182223..463737d3 100644 --- a/docs/Tools/Git.md +++ b/docs/Tools/Git.md @@ -10,7 +10,7 @@ tags: !!! info "Docs" - [Command 汇总](https://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html) - [Learn Branch :一个分支的练习\学习网站](https://learngitbranching.js.org/?locale=zh_CN) - - 推荐阅读:ProGit + - 推荐阅读:ProGit [英文](https://git-scm.com/book/en/v2) ## Git 配置 @@ -20,6 +20,7 @@ tags: ```c++ $ git config --global user.name "ZZIcarus" $ git config --global user.email 2450606426@qq.com +$ git config --list ``` ## gitignore @@ -69,9 +70,10 @@ git diff git push origin main git pull origin main - ``` +### 文件操作 +- `git rm ` 删除 ### 版本回退 HEAD表示最新版本,HEAD^,HEAD^^,HEAD~100表示前一个、前两个、前100个版本 diff --git "a/docs/Tools/Unix Command\345\244\207\345\277\230.md" "b/docs/Tools/Unix Command\345\244\207\345\277\230.md" deleted file mode 100644 index 11a2c652..00000000 --- "a/docs/Tools/Unix Command\345\244\207\345\277\230.md" +++ /dev/null @@ -1,2 +0,0 @@ -# command -## 文件 diff --git "a/docs/Tools/Unix\345\221\275\344\273\244.md" "b/docs/Tools/Unix\345\221\275\344\273\244.md" new file mode 100644 index 00000000..df930153 --- /dev/null +++ "b/docs/Tools/Unix\345\221\275\344\273\244.md" @@ -0,0 +1,12 @@ +# 命令备忘 + +## 文件操作 + +## + +## 软件更新/安装 + +## 其他 + +- 解压缩:`tar -xvzf linux-6.11-rc7.tar.gz` +- \ No newline at end of file diff --git a/docs/Tools/gcc & gdb.md b/docs/Tools/gcc & gdb.md new file mode 100644 index 00000000..35de29fc --- /dev/null +++ b/docs/Tools/gcc & gdb.md @@ -0,0 +1,24 @@ +--- +tags: + - doing + - Tools/GCC +statistics: true +title: NOTE +author: zzicarus +date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +--- + +# GCC +默認情況下,進行 gcc 编译生成的是 release 版本的可执行文件,如果要进行 debug 要去实现 debug 版本 +## 基本编译 +- `gcc -o file.c` 对单文件生成可执行文件 +- `gcc -c file.c` 只进行编译而不进行链接,/为可选值 +- `gcc -S test` 生成汇编代码 +- `gcc -O2 -o output file.c` 编译优化 +- `gcc -g -o output file.c` 生成调试信息 +- `gcc -std=c11 -o ...` 指定版本 +- `gcc -Wall -o output file.c` 开启编译器警告 +- `gcc -D MACRO_NAME=value -o output file.c` 定义宏 +- `gcc -I/path/to/include -o output file.c` 指定寻找目录(在 makefile 中可用作查询路径) + \ No newline at end of file diff --git a/docs/Tools/gdb.md b/docs/Tools/gdb.md new file mode 100644 index 00000000..06ed6933 --- /dev/null +++ b/docs/Tools/gdb.md @@ -0,0 +1,16 @@ +--- +tags: + - doing + - Tools/GDB +statistics: true +title: NOTE +author: zzicarus +date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +--- + +# GDB +- [Debugging With GDB](https://sourceware.org/gdb/current/onlinedocs/gdb.html/) +- [100个GDB技巧](https://wizardforcel.gitbooks.io/100-gdb-tips/content/) +- [GDB备忘](https://note.tonycrane.cc/cs/tools/gdb/) + diff --git a/docs/Tools/index.md b/docs/Tools/index.md index 02aa47d8..04e1d395 100644 --- a/docs/Tools/index.md +++ b/docs/Tools/index.md @@ -9,5 +9,8 @@ | [[GNUMake]] | **资料:** [makefile 介绍 — 跟我一起写 Makefile 1.0 文档](https://seisman.github.io/how-to-write-makefile/introduction.html)
**视频:** [一个较简单的入门 ](https://www.youtube.com/watch?v=E1_uuFWibuM&t=1152s) | | [[git]] | [廖雪峰Git入门](../../asset/PDF/Git.pdf)
[Progit](https://github.com/progit/progit2) | | [[Tools/Shell\|Shell]] | | -| | | +| [[Unix命令]] | | +| [[Docker]] | | +| [[正则表达式]] | | +| [[gcc & gdb]] | | ![[Collection]] \ No newline at end of file diff --git "a/docs/Tools/\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217.md" "b/docs/Tools/\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217.md" index 56c94d0c..0d8e3076 100644 --- "a/docs/Tools/\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217.md" +++ "b/docs/Tools/\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217.md" @@ -6,5 +6,6 @@ tags: !!! info "" - +https://regexlearn.com/zh-cn/cheatsheet +## 锚定 ## diff --git a/docs/_templates/_read.md b/docs/_templates/_read.md new file mode 100644 index 00000000..7753e3c9 --- /dev/null +++ b/docs/_templates/_read.md @@ -0,0 +1,9 @@ +--- +tags: + - doing +Statistics: true +Title: Reading +Author: zzicarus +date: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +update: <% tp.date.now("YYYY-MM-DD HH:mm:ss") %> +--- diff --git a/mkdocs.yml b/mkdocs.yml index f0553d5b..dd8d35b9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -190,6 +190,21 @@ nav: - 4 Processor: CS/CO/4_Processor.md - 5 Speed and Size: CS/CO/5_.md - 6 IO: CS/CO/6.md + + - OS: + - CS/OS/index.md + - 1 Overview: CS/OS/Ch1_Overview.md + - 2 Process: CS/OS/Ch2_Process.md + - 3 Thread: CS/OS/Ch3_Thread.md + - CN: + - CS/CN/index.md + - 1 Overview: CS/CN/Overview.md + - 2 Physical Layer: CS/CN/Physical Layer.md + - 3 Data Link Layer: CS/CN/Data Link Layer.md + - 4 Network Layer: CS/CN/Network Layer.md + - 5 Transport Layer: CS/CN/Transport Layer.md + - 6 Application Layer: CS/CN/Application Layer.md + - DIP: - 期末复习: CS/DIP/DIP_Review.md - 【短学期】大数据可视化: CS/大数据可视化.md