Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add much important content and ready to be publish first
Signed-off-by: hylerrix <hylerrix@gmail.com>
- Loading branch information
Showing
14 changed files
with
2,693 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
# 操作系统 | ||
|
||
线程与进程 | ||
## 什么是线程与进程? | ||
|
||
- 进程是 CPU 资源分配的最小单位,是能拥有资源和独立运行的最小单位 | ||
- 线程是 CPU 调度的最小单位,线程是建立在进程的基础上的一次程序运行单位,一个进程中可以有多个线程 | ||
|
||
• 进程 | ||
• 资源分配最小单位 | ||
• 有自己的独立地址空间,系统会建立数据表来维护代码段、堆栈段和数据段 | ||
• 进程间的通信需要以通信的方式(IPC)进行 | ||
• 多进程程序更健壮 | ||
• 同步:无名管道、有名管道、信号、共享内存、消息队列、信号量 | ||
• 僵尸进程:子进程退出时父进程没有获取其最新状态的子进程(ps 命令的 defunct 京城状态) | ||
• 孤儿进程:父进程运行结束时子进程还在运行时 | ||
• 线程 | ||
• 程序执行的最小单位 | ||
• 是共享中的数据,使用相同的地址空间(开销小) | ||
• 同一进程下的线程间共享全局变量、静态变量等数据 | ||
• 多线程见需要处理好同步和互斥,否则一个线程死掉整个进程死掉 | ||
• 同步:互斥量、读写锁、自旋锁、线程信号、条件变量 | ||
* 进程 | ||
* 资源分配最小单位 | ||
* 有自己的独立地址空间,系统会建立数据表来维护代码段、堆栈段和数据段 | ||
* 进程间的通信需要以通信的方式(IPC)进行 | ||
* 多进程程序更健壮 | ||
* 同步:无名管道、有名管道、信号、共享内存、消息队列、信号量 | ||
* 僵尸进程:子进程退出时父进程没有获取其最新状态的子进程(ps 命令的 defunct 京城状态) | ||
* 孤儿进程:父进程运行结束时子进程还在运行时 | ||
* 线程 | ||
* 程序执行的最小单位 | ||
* 是共享中的数据,使用相同的地址空间(开销小) | ||
* 同一进程下的线程间共享全局变量、静态变量等数据 | ||
* 多线程见需要处理好同步和互斥,否则一个线程死掉整个进程死掉 | ||
* 同步:互斥量、读写锁、自旋锁、线程信号、条件变量 | ||
|
||
## 什么是 CPU 和 GPU? | ||
|
||
* CPU:每个核心可以处理多个任务 | ||
* GPU:图形处理,每个单元只能处理有限的任务,可以工作在多个核心之间 | ||
|
||
## 线程和协程如何对比? | ||
|
||
* 在计算机科学中还有一个概念叫做 Fiber,英文含义就是“纤维”,意指比 Thread 更细的线,也就是比线程(Thread)控制得更精密的并发处理机制。 | ||
|
||
## 并行和并发的机制和区别? | ||
|
||
* 并行可以是并发,而并发不一定是并行。并行一般需要物理层面的支持。 |
Oops, something went wrong.