请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

这个英文的进程线程类比可不可以发一下网址,我觉得说的很精炼

正在回答 回答被采纳积分+3

1回答

ccmouse 2021-07-16 15:05:57
http://www.differencebetween.info/difference-between-process-and-thread
Key difference: Thread and Process are two closely related terms in multi-threading. The main difference between the two terms is that the threads are a part of a process, i.e. a process may contain one or more threads, but a thread cannot contain a process.

In programming, there are two basic units of execution: processes and threads. They both execute a series of instructions. Both are initiated by a program or the operating system. This article helps to differentiate between the two units.

process.jpgA process is an instance of a program that is being executed. It contains the program code and its current activity. Depending on the operating system, a process may be made up of multiple threads of execution that execute instructions concurrently. A program is a collection of instructions; a process is the actual execution of those instructions.

A process has a self-contained execution environment. It has a complete set of private basic run-time resources; in particular, each process has its own memory space. Processes are often considered similar to other programs or applications. However, the running of a single application may in fact be a set of cooperating processes. To facilitate communication between the processes, most operating systems use Inter Process Communication (IPC) resources, such as pipes and sockets. The IPC resources can also be used for communication between processes on different systems. Most applications in a virtual machine run as a single process. However, it can create additional processes using a process builder object.

thread.jpg

In computers, a thread can execute even the smallest sequence of programmed instructions that can be managed independently by an operating system. The applications of threads and processes differ from one operating system to another. However, the threads are made of and exist within a process; every process has at least one. Multiple threads can also exist in a process and share resources, which helps in efficient communication between threads.

On a single processor, multitasking takes place as the processor switches between different threads; it is known as multithreading. The switching happens so frequently that the threads or tasks are perceived to be running at the same time. Threads can truly be concurrent on a multiprocessor or multi-core system, with every processor or core executing the separate threads simultaneously.

In summary, threads may be considered lightweight processes, as they contain simple sets of instructions and can run within a larger process. Computers can run multiple threads and processes at the same time.

Comparison between Process and Thread:


Process

Thread

Definition

An executing instance of a program is called a process.

A thread is a subset of the process.

Process

It has its own copy of the data segment of the parent process.

It has direct access to the data segment of its process.

Communication

Processes must use inter-process communication to communicate with sibling processes.

Threads can directly communicate with other threads of its process.

Overheads

Processes have considerable overhead.

Threads have almost no overhead.

Creation

New processes require duplication of the parent process.

New threads are easily created.  

Control

Processes can only exercise control over child processes.

Threads can exercise considerable control over threads of the same process.

Changes

Any change in the parent process does not affect child processes.

Any change in the main thread may affect the behavior of the other threads of the process.

Memory

Run in separate memory spaces.

Run in shared memory spaces.

File descriptors

 

Most file descriptors are not shared.

It shares file descriptors.

File system

There is no sharing of file system context.

It shares file system context.

Signal

It does not share signal handling.

It shares signal handling.

Controlled by

Process is controlled by the operating system.

Threads are controlled by programmer in a program.

Dependence

Processes are independent.

Threads are dependent.



1 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信