process进程 and threads线程 之间的关系

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
  • Must then have storage for thread details, multiple program counters in PCB

进程只有一个执行线程

一个进程可能有多个程序计数器

多个位置可同时执行 多个控制线程

必须在PCB 中存储线程细节和多个程序计数器

Relation

线程是进程的执行单元,属于进程并共享进程的资源。一个进程可以有多个线程,但一个线程只能属于一个进程。

6095e9018d754ffb8242f5279a57156f.pnga3780be213aa4c239f9c931c0e453fef.png

个人理解 线程thread更像是小但团队协作的进程process,相对进程能够共享数据,效率高,但是因为线程有关联,当一个线程被阻塞的时候,所有线程都被阻塞了

  • 19
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值