The difference between process line Cheng

Source: Internet
Author: User

First, the concept

1. Process

A process is a program with a certain independent function about a single run activity on a data set, a process that is an independent unit of the system's resource allocation and scheduling. Each process has its own independent memory space, and different processes communicate through interprocess communication. Because the process compares the weight and occupies the independent memory, the switching overhead between the context processes (stacks, registers, virtual memory, file handles, etc.) is large, but relatively stable and secure.

2. Threads

A thread is an entity of a process that is the basic unit of CPU dispatch and dispatch, which is a smaller unit that can run independently than a process. The thread itself basically does not own the system resources, only has a point in the operation of the necessary resources (such as program counters, a set of registers and stacks), However, it can share all of the resources owned by the process with other threads that belong to one process. Inter-thread communication is mainly through shared memory, the context switches quickly, the resource overhead is low, but the data is easily lost compared to the process is not stable.

3. Co-process

The process is a kind of user-state lightweight thread, the scheduling of the process is entirely user-controlled. The co-process has its own register context and stack. When the scheduling switch, the register context and the stack is saved to another place, in the cut back, restore the previously saved register context and stack, the direct Operation Stack is basically no kernel switching overhead, can not lock the access to global variables, so the context of the switch is very fast.

Second, the difference:

1, process and thread comparison

A thread is an execution unit within a process and a scheduler within a process. The difference between a thread and a process:
1) address space: A thread is an execution unit within a process that has at least one thread that shares the address space of the process, and the process has its own independent address space
2) Resource ownership: A process is a resource allocation and owned unit, and a thread in the same process shares the resources of the process
3) The thread is the basic unit of the processor dispatch, but the process is not
4) Both can be executed concurrently

5) Each individual thread has a program run entry, sequence of sequence execution and exit of the program, but the thread cannot execute independently, must be dependent on the application, and the application provides multiple threads to execute control

2, co-multithreading and threads to compare

1) One thread can have multiple threads, and a process can have multiple co-processes independently, so that a multi-core CPU can be used in Python.

2) thread processes are synchronous, and the co-process is asynchronous

3) The process can retain the state of the last call, and each time it is re-entered, it is equivalent to the state of the last call.

The difference between process line Cheng

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.