Process Concept
- An operating system executes a variety of programs that run as a process.
- Process – a program in execution; process execution must progress in sequential fashion. No parallel execution of instructions of a single process
- Multiple parts
- The program code, also called text section
- Current activity including program counter, processor registers
- Stack containing temporary data
- Function parameters, return addresses, local variables
- Data section containing global variables
- Heap containing memory dynamically allocated during run time
操作系统负责执行各种程序,这些程序在执行时被称作进程。
进程的执行必须按顺序进行(progress in sequential fashion)。
- Program is passive entity stored on disk (executable file); process is active
- Program becomes process when an executable file is loaded into memory
- Execution of program started via GUI mouse clicks, command line entry of its name, etc.
- One program can be several processes
- Consider multiple users executing the same program
程序是存储在硬盘上的被动实体(可执行文件),进程是主动的
当可执行文件载入内存时,程序就变成了进程
通过图形用户界面鼠标点击、命令行输入程序名等方式启动程序的执行。
一个程序可以是多个进程
考虑多个用户执行同一个程序
Threads
- So far, process has a single thread of execution
- Consider having multiple program counters per process
- Multiple locations can execute at once
- Multiple threads of control -> threads
- Multiple locations can execute at once
- Must then have storage for thread details, multiple program counters in PCB
进程只有一个执行线程
一个进程可能有多个程序计数器
多个位置可同时执行 多个控制线程
必须在PCB 中存储线程细节和多个程序计数器
Relation
线程是进程的执行单元,属于进程并共享进程的资源。一个进程可以有多个线程,但一个线程只能属于一个进程。
个人理解 线程thread更像是小但团队协作的进程process,相对进程能够共享数据,效率高,但是因为线程有关联,当一个线程被阻塞的时候,所有线程都被阻塞了