What is the difference between a process and a thread?

Source: Internet
Author: User

Threads: sometimes referred to as lightweight processes (lightweight PROCESS,LWP), is the smallest unit of program execution flow. is a collection of instructions.
A thread is a single sequential control flow in a program. A relatively independent and scheduled execution unit in the process is the basic unit for the system to dispatch and dispatch the CPU independently, which refers to the dispatching unit of the running program.
Running multiple threads at the same time in a single program accomplishes different tasks, called multithreading.

Process: QQ to a whole form of exposure to the operating system management, which contains a variety of resource calls, memory management, network interface calls, etc...
A collection of various resource management can be a process.

Process to operate the CPU, you must first create a thread,
All the threads in a process has the same view of the memory
All threads in the same process share the same block of memory space.

What is the difference between a process and a thread?
threads share the address space of the process that created  It; processes have their own address space. Thread shared memory space, process memory is independent Threads have  direct access to the data segment of its process; processes  have their own copy of the data segment of the parent  process. A thread can access its own data segment directly, and the process needs to replicate the data segment of its parent process threads can directly communicate with  other threads of its process; processes must use interprocess  communication to communicate with sibling  Processes. The threads of the same process can communicate directly, and two processes want to communicate and must be implemented through an intermediary agent New threads are easily created; new  processes require duplication of the parent process. Creating a new thread is simple,  Creating a new process requires one clone of its parent process Threads can exercise considerable&nbsP;control over threads of the same process; processes can only  exercise control over child processes. A thread can control and manipulate other threads in the same process, but the process can only manipulate child processes changes  to the main thread  (cancellation, priority change, etc.)  may affect the behavior of the other threads of the  Process; changes to the parent process does not affect child  processes.

Changes to the main thread (cancellation, priority change, and so on) may affect the behavior of the other threads of the process, and changes to the parent process do not affect the child process.

What is the difference between a process and a thread?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.