Program Thread 和 Process的不同点

  • 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工作时期的技术积累和国外初创公司的经验总结?

敬请关注:

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

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

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

原文地址:https://www.cnblogs.com/vigorz/p/10504045.html

时间: 2024-10-08 08:34:32

Program Thread 和 Process的不同点的相关文章

43_2013年11月22日 线程池 Socket(Thread Lock Process 摇奖 线程池ThreadPool)

1>模拟线程池,生产者消费者问题 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Product { class Program { static void Main(string[] args) { //创建一个池子 MyConncetion[]

Thread VS Process From Stackoverflow

Preface:翻译水平渣,阅读需仔细.有错误欢迎指正. What is the difference between a thread and a process? 线程和进程之间有何区别? Processes vs Threads 进程VS线程 A process is an executing instance of an application. What does that mean? Well, for example, when you double-click the Micro

[CareerCup] 16.1 Thread and Process 线程和进程

16.1 What's the difference between a thread and a process? 进程Process是程序执行时的一个实例.一个进程是被分配系统资源的独立单元,每个进程在独立的地址空间上执行,如果需要使用其他进程的资源,需要使用进程间通讯,包括管道Pipes,文件Files,套接字Sockets,或者其他形式. 线程Thread存在于进程之中并分享进程的资源(包括堆空间).同一个进程中的多个线程分享同一个堆地址.这是和进程区别很大的地方,进程之间不能直接访问内

how kernel distinguishes between thread and process

https://stackoverflow.com/questions/36213681/how-kernel-distinguishes-between-thread-and-process 原文地址:https://www.cnblogs.com/yudidi/p/12417285.html

Difference between Process and thread?

What are the differences between a process and a thread? How are they similar? How can 2 threads communicate? How can 2 process communicate? Both processes and threads are independent sequences of execution. The main difference is that threads (of th

【APUE】Chapter8 Process Control

这章的内容比较多.按照小节序号来组织笔记的结构:再结合函数的示例带代码标注出来需要注意的地方. 下面的内容只是个人看书时思考内容的总结,并不能代替看书(毕竟APUE是一本大多数人公认的UNIX圣经). 8.2 Process Identifiers 1. unix system给系统分配进程pid采用的是delay reuse策略:即,刚用完被释放的pid不会马上分配给新的进程,目的是防止新进程错误使用与之前进程相同的ID(这块内容还没太懂,以后再看):但具体等多久不一定. 2. 有几个特殊的p

C# Self Injector into non managed process

Hey all, I'm gonna explain you how make a self injecting program in C#.I hope you guys thinks its usefull and have a nice reading  Requirements:Visual Studio 20xx (I use Visual Studio 2010)VInj (A nice library to inject managed dll's, its can be down

How to Analyze Java Thread Dumps--reference

原文地址:http://architects.dzone.com/articles/how-analyze-java-thread-dumps The Performance Zone is presented by AppDynamics. AppDynamics is a leaders in the APM space with massive cost reductions for users. The content of this article was originally wri

java thread reuse(good)

I have always read that creating threads is expensive. I also know that you cannot rerun a thread. I see in the doc of Executors class: Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they