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 the same process) run in a shared memory space, while processes run in separate memory spaces. Lets see the differences in detail:

Thread vs Process

1) A program in execution is often referred as process. A thread is a subset(part) of the process.

2) A process consists of multiple threads. A thread is a smallest part of the process that can execute concurrently with other parts(threads) of the process.

3) A process is sometime referred as task. A thread is often referred as lightweight process.

4) A process has its own address space. A thread uses the process’s address space and share it with the other threads of that process.

5)

Per process items             | Per thread items
------------------------------|-----------------
Address space                 | Program counter
Global variables              | Registers
Open files                    | Stack
Child processes               | State
Pending alarms                |
Signals and signal handlers   |
Accounting information        |

6) A thread can communicate with other thread (of the same process) directly by using methods like wait(), notify(), notifyAll(). A process can communicate with other process by using inter-process communication.

7) New threads are easily created. However the creation of new processes require duplication of the parent process.

8) Threads have control over the other threads of the same process. A process does not have control over the sibling process, it has control over its child processes only.

Process:

  • Process is basically a program in execution. It is an active entity.
  • Some operating systems use the term ‘task‘ to refer to a program that is being executed.
  • A process is always stored in the main memory also termed as the primary memory or random access memory.
  • Therefore, a process is termed as an active entity. It disappears if the machine is rebooted.
  • Several process may be associated with a same program.
  • On a multiprocessor system, multiple processes can be executed in parallel.
  • On a uni-processor system, though true parallelism is not achieved, a process scheduling algorithm is applied and the processor is scheduled to execute each process one at a time yielding an illusion of concurrency.
  • Example: Executing multiple instances of the ‘Calculator’ program. Each of the instances are termed as a process.

Thread:

  • A thread is a subset of the process.
  • It is termed as a ‘lightweight process’, since it is similar to a real process but executes within the context of a process and shares the same resources allotted to the process by the kernel.
  • Usually, a process has only one thread of control – one set of machine instructions executing at a time.
  • A process may also be made up of multiple threads of execution that execute instructions concurrently.
  • Multiple threads of control can exploit the true parallelism possible on multiprocessor systems.
  • On a uni-processor system, a thread scheduling algorithm is applied and the processor is scheduled to run each thread one at a time.
  • All the threads running within a process share the same address space, file descriptors, stack and other process related attributes.
  • Since the threads of a process share the same memory, synchronizing the access to the shared data withing the process gains unprecedented importance.

原文地址:https://www.cnblogs.com/lightwindy/p/9808299.html

时间: 2024-10-15 11:32:19

Difference between Process and thread?的相关文章

IOS 多线程漫漫谈(Process and Thread)

前言 时间就是一把杀猪刀,岁月更是毫不留情的在我英俊的脸上留下痕迹!恨呀,这就开始了我的社会之旅.2015年上海,在拉钩网中投遍了IOS实习岗,两家面试!在面试中受到的打击着实不清呀,其中心酸就不一一道来了.在学校时候学的不认真,学习的时候又没有笔记,知识在又没有实际的项目实践,最后的结果就是什么都知道都听过,但是具体的什么都说不出来!所以毅然决然的决定投身于写博客的大队伍中,与各位共勉. (PS:既然是社会之旅,除了技术的敲门砖,当然还有就是做人了!我只能说我被HR给刷过) 漫漫谈(Proce

Program, Process and Thread

A program is an executable file store. A process is a running program. A thread is a single sequence stream within a process.

Process And Thread

当一个应用组件开启,并且这个应用没有其他任何组件运行,安卓系统为这个程序启动一个新的Linux进程,用单个线程进行.默认,同一个应用的所有组件在同一个进程和线程(叫做主线程)中.如果一个应用组件开启,并且这个应用已经有一个存在进程(因为这个程序的另一个组件存在),然后这个组件被在那个进程中启动并且使用同一线程执行.然后,我们可以安排程序中的不同组件在独立的进程中运行,并且我们可以为任何进程创建额外的线程. 这个文档讨论进程和线程如何在安卓应用中工作. Processes 默认,同一个应用的所有组

进程(process)线程(thread)应用程序域(domain) (from www.sysoft.cc)

进程(process)是windows的一个基本概念,它包括了运行一个程序的需要的所有资源.进程之间是相互独立的,一个进程无法访问另一个进程之间的数据(除非采用分步式计算方式),一个进程运行的失败也不会影响到另一个进程的运行.windows就是利用进程将工作划分为多个工作区域的.进程可以理解为一个程序 的基本边界.解决问题:要解决并发问题,即:使进程独立,就要使每个进程有属于自己的程序段,数据段,进程控制块. 应用程序域(domain),它提供安全通用的处理单元,公共语言运行库可以用它来进行应用

Process进程 ; Thread线程

<> 前台线程和后台线程 InvokeHelper:跨线程访问/修改主界面控件方法.属性 C#线程用法及跨线程访问 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace 进程Process { /// <summary> /// Process类是一个非静态类.它里面包含静态成员和非静态成员.静

android 开发-Process and Thread

目录 1 android中进程与线程 - Processes and Threads 1.1 进程 - Processes 1.1.1 进程的生命期 1.2 线程 - Threads 1.2.1 工作线程 - Worker threads 1.2.2 使用-AsyncTask 1.2.3 线程安全的方法 - Thread-safe methods 1.3 进程间通信 - Interprocess Communication android中进程与线程 - Processes and Thread

What is the difference between task and thread?

http://stackoverflow.com/questions/4130194/what-is-the-difference-between-task-and-thread 回答一: A task is something you want done. A thread is one of the many possible workers which performs that task. In .NET 4.0 terms, a Task represents an asynchron

process vs thread

6.进程与线程的区别:系统调度是对进程还是线程,线程与进程共享的内存空间.公共地址空间等: A.操作系统只调度进程,不调度线程 B.线程共享内存地址空间,进程不共享 C.线程间可共享内存数据,但进程不可以 D.进程可以通过IPC通信,但线程不可以7.内存管理:段页式管理,地址映射表是?(操作系统方面的知识也不能掉以轻心呀) A. 每个作业或进程一张段表,一张页表 B. 每个作业或进程的每个段一张段表,一张页表 C. 每个作业或进程一张段表,每个段一张页表 D. 每个作业一张页表,每个段一张段表

《Cracking the Coding Interview》——第16章:线程与锁——题目1

2014-04-27 19:09 题目:线程和进程有什么区别? 解法:理论题,操作系统教材上应该有很详细的解释.我回忆了一下,写了如下几点. 代码: 1 // 16.1 What is the difference between process and thread? 2 Answer: 3 Process: 4 1. Basic element of resource allocation in the operating system. 5 2. Possesses independent