Program Thread 和 Process的不同点

作者: V哥的博客 | 来源:发表于2019-03-09 13:13 被阅读6次
  • Thread is for execution
    • Kernel level thread, physical parallelism
      • Cores Divide work amount of physical cores / CPU
      • Load balancing
      • Data Splitting
        • Which will lead to data dependency coodination and message passing
      • Bad thing for multiple cores is this is hard for Testing and debugging
    • User level thread only have logical parallelism
      • Example, Read from user input is blocking; we have to work on it to make it logical parallelism
  • Process is for resource

What is Program

Program是一个存在disk中且断电或重启不会消失可执行文件,存储在存储媒介中,以实体文件的形态存在

A program is an executable file residing on the disk (secondary storage) in a directory. It is also termed as a set of instructions stored in the secondary storage device that are intended to carry out a specific job. It is read into the primary memory and executed by the kernel.

本文来自 Abbymz 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/Abby210/article/details/51225034?utm_source=copy

或者可以称之为persistently 的文件,断电也不会消失。

What is Process ?

当program被执行之后,就变成了进程。执行者的权限和程序所需的资料都会载入到内存中,OS会给予这些内存单元一个pid。

Unit of resource ownership (allocation) and unit of protection

text, Code of Programmer
Data
Heap
Stack

一个program可以创建出很多个进程,关机或停电会死掉

Process的组成

  • Permission user or kernel
  • Priority
  • Files
  • ID
    • PID
    • PPID
    • Folk
    • UserID
  • Protected access to
    • Processors
    • other process
    • Files
    • I/O
  • A virtual space that holds the process image

What is Thread ?

线程称之为Lightweight Process,一个进程可以有多个线程,他们共享一片内存

  • has access to the same data
    • When one thread alters a data, other threads see the results
    • When one thread open a file, other threads can also access that file.

Unit of dispatch or unit of execution

多线程的好处

  • 开启线程要快于开启进程
  • 关闭线程要快于关闭进程
  • 切换线程要快于切换进程
  • 线程可以相互通讯

什么叫Multithreading

The ability of an OS to support multiple, concurrent paths of execution within a single process.

Process and thread states

  • Ready
    • new process usually set as read state
    • At this time scheduler is not pick it up yet.
      • If it get picked by scheduler and running in CPU, then goes to Running State
      • If it get external event, something like lock, then goes to block
  • Running,
    • Scheduler picked it up, and CPU is run this instruction
      • If it get finished, goes to Exit states
      • If it get IO interrupts, goes to ready, blocked status
      • If it can not get the resource which is conflict with other process, goes to deadlock
  • Block
    • If it lock (wait able ) is release, or IO is completed, then goes to Ready
  • Deadlock
  • Exit (Zombie State)
    • When process is finished, waiting for cleaning up

How Deadlock happen ?

  • When process A has resource a, and it need resource b from process B.
  • At the same time, process B need resource a from A
  • Then those process gonna have deadlock due to both of them can get the resource they need.

Reference

https://slideplayer.com/slide/5219996/


想要看到更多玮哥的学习笔记、考试复习资料、面试准备资料?想要看到IBM工作时期的技术积累和国外初创公司的经验总结?

image

敬请关注:

玮哥的博客 —— CSDN的传送门

玮哥的博客 —— 简书的传送门

玮哥的博客 —— 博客园的传送门

相关文章

  • Program Thread 和 Process的不同点

    Thread is for executionKernel level thread, physical para...

  • 浏览器的进程

    进程 (process) 和线程 (thread) 进程(process)和线程(thread)是操作系统的基本概...

  • 46. 分布式进程

    在Thread和Process中,应当优选Process,因为Process更稳定,而且,Process可以分布到...

  • Android面试之Thread

    ## Thread 相关知识点整理 1,Thread的作用,Process和Thread的区别 2,Thread的...

  • 进程和线程

    进程和线程 什么是进程(process)? An executing instance of a program ...

  • Java线程

    可以通过Process中的exitValue()配合Thread.sleep()和Process中的destroy...

  • Linux_130_进线程

    1.Linux下存在process和thread这两种操作系统基本概念process是进程,thread是线程计算...

  • SDP 课下总结

    Process: A sequence of operations performed by a program ...

  • Chapter 17 程序管理与SElinux初探

    1. 什么是程序 (Process) 1.1 一些基础概念 process & program Process 是...

  • segment & vma

    references: Process Segments and VMA Anatomy of a Program...

网友评论

    本文标题:Program Thread 和 Process的不同点

    本文链接:https://www.haomeiwen.com/subject/physpqtx.html