Brief analysis of operating system threads, processes, and routines

Source: Internet
Author: User
First, the concept

1. Process

A process is a program with a certain independent function about a running activity on a data set, and a process is an independent unit of resource allocation and scheduling for a system. Each process has its own independent memory space, and different processes communicate through interprocess communication. Because process comparison weight, occupy the independent memory, so the switching overhead (stack, register, virtual memory, file handle and so on) between the context process is bigger, but relatively stable security.

2, Thread

A thread is an entity of a process, the basic unit of CPU scheduling and dispatching, and it is a unit that can operate independently, smaller than a process. The thread itself has essentially no system resources, only a few of the necessary resources in operation (such as program counters, a set of registers and stacks), However, it can share all the resources owned by the process with other threads belonging to one process. The communication between threads is mainly through shared memory, the context switch is very fast, the resource cost is low, but it is easy to lose data compared with the process.

3. Co-process
The coprocessor is a user-state lightweight thread, and the scheduling of the coprocessor is completely controlled by the user. The coprocessor has its own register context and stack. When scheduling switch, the register context and stack are saved to other places, in the 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, more process and thread comparison

A thread is a unit of execution within a process and a scheduled entity within a process. The difference between a thread and a process:

1 address space: A thread is an execution unit within a process in which there is at least one thread that shares the address space of the process, and the process has its own separate address space
2 Resource ownership: Processes are resource allocation and ownership units, and threads in the same process share the resources of the process
3 The thread is the base unit of the processor dispatch, but the process is not
4) Both can be executed concurrently
5 each independent thread has a program to run the entry, sequence execution sequence and program exit, but the thread can not be executed independently, must be dependent on the application, the application provides multiple thread execution control

2, the association Chengdo and the thread comparison

1 A thread can have multiple threads, and a process can have more than one coprocessor, so python can use multi-core CPUs.
2 The thread process is a synchronization mechanism, while the coprocessor is asynchronous
3 The process can preserve the state of the last call, and each time the procedure is entered, it is equivalent to the state of the last call

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.