线程和进程之间的区别_进程和线程之间的区别
线程和进程之间的区别
Here you will learn about difference between process and thread i.e. process vs thread.
在这里,您将了解进程与线程之间的区别,即进程与线程之间的区别。
Process: In simple words a process is executing a program. But not all, it’s only an instance of a computing program. Several processes may be associated with the same program. Process contains program code and its current activity.
流程:简单来说,就是流程正在执行程序。 但是,并非全部,这只是计算程序的一个实例。 多个进程可能与同一程序相关联。 流程包含程序代码及其当前活动。
Thread: We can say thread is a light weight process. A thread of execution is the smallest sequence of programmed instructions that can be managed independently by scheduler. Threads reside inside the process. Each thread belongs to exactly one process. No thread exists outside the process.
线程:我们可以说线程是一个轻量级的过程。 执行线程是可以由调度程序独立管理的已编程指令的最小序列。 线程驻留在进程内部。 每个线程恰好属于一个进程。 进程外没有线程。
Image Source
图片来源
进程与线程–进程与线程之间的区别 (Process vs Thread – Difference between Process and Thread)
Process | Thread |
1) System calls involved in process. | 1) No system calls involved. |
2) Context switching required. | 2) No context switching required. |
3) Different process have different copies of code and data. | 3) Sharing same copy of code and data can be possible among different threads.. |
4) Operating system treats different process differently. | 4) All user level threads treated as single task for operating system. |
5) If a process got blocked, remaining process continue their work. | 5) If a user level thread got blocked, all other threads get blocked since they are treated as single task to OS. (Noted: This is can be avoided in kernel level threads). |
6) Processes are independent. | 6) Threads exist as subsets of a process. They are dependent. |
7) Process run in separate memory space. | 7) Threads run in shared memory space. And use memory of process which it belong to. |
8) Processes have their own program counter (PC), register set, and stack space. | 8) Threads share Code section, data section, Address space with other threads. |
9) Communication between processes requires some time. | 9) Communication between processes requires less time than processes. |
10) Processes don’t share the memory with any other process. | 10) Threads share the memory with other threads of the same process |
11) Process have overhead. | 11) Threads have no overhead. |
处理 | 线 |
1)参与过程的系统调用。 | 1)不涉及系统调用。 |
2)需要上下文切换。 | 2)不需要上下文切换。 |
3)不同的过程具有不同的代码和数据副本。 | 3)可以在不同线程之间共享相同的代码和数据副本。 |
4)操作系统对不同的进程有不同的对待。 | 4)所有用户级线程都被视为操作系统的单个任务。 |
5)如果某个进程被阻塞,其余进程将继续其工作。 | 5)如果用户级线程被阻止,则所有其他线程都被阻止,因为它们被视为OS的单个任务。 (注意:在内核级线程中可以避免这种情况)。 |
6)流程是独立的。 | 6)线程作为进程的子集存在。 他们是依赖的。 |
7)进程在单独的内存空间中运行。 | 7)线程在共享内存空间中运行。 并使用它所属的进程的内存。 |
8)进程具有自己的程序计数器(PC),寄存器集和堆栈空间。 | 8)线程与其他线程共享代码部分,数据部分,地址空间。 |
9)流程之间的通信需要一些时间。 | 9)流程之间的通信所需时间少于流程。 |
10)进程不与任何其他进程共享内存。 | 10)线程与同一进程的其他线程共享内存 |
11)过程有开销。 | 11)线程没有开销。 |
Threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications. Another difference between thread and process is that threads within the same process share the same address space, whereas different processes do not.
线程用于小型任务,而进程用于更多的“重量级”任务-基本上是应用程序的执行。 线程与进程之间的另一个区别是,同一进程内的线程共享相同的地址空间,而不同的进程则不共享。
翻译自: https://www.thecrazyprogrammer.com/2018/01/difference-process-thread.html
线程和进程之间的区别
还没有评论,来说两句吧...