Linux system Programming--differences and linkages between processes and threads

Source: Internet
Author: User

In many classic operating system textbooks, the process is always defined as an execution instance of a program, it does nothing, it only maintains the various resources required by the application, while the thread is the real execution entity.


The process must contain at least one thread in order for the process to do some work.



Process, intuitive Point said, saved on the hard disk after the program run, will be in the memory space to form a separate memory body, the memory body has its own address space, has its own heap, the superior unit is the operating system. The operating system allocates system resources in the process, so we also say that the process is the smallest unit of resource allocation . For more details, see the introduction to the process.


The thread exists and processes, which is the smallest unit of operating system scheduling execution. In the popular point , the thread is the work.


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. 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 does not own the system resources, it has only a few resources (such as program counters, a set of registers and stacks) that are essential in the run, but it can share all the resources owned by the process with other threads belonging to one process.


If the process is a resource steward, responsible for the resources from the owner, then the thread is the work of Labor. A housekeeper must complete a job, requiring at least one laborer, that is, a process contains at least one thread, or it can contain multiple threads. Labor to work, you need to rely on the housekeeper, so say a thread, must belong to a certain process. The process has its own address space, the thread uses the process's address space, that is, the resources in the process, the threads are authorized to access, such as heap ah, stack ah, static storage area and so on.


The thread is a proletariat, but the proletariat work, must have their own labor tools, this labor tool is the stack, the thread has its own stack, the stack is still using the process of the address space, but this space is marked as a thread for the stack. Each thread will have its own private stack, which cannot be accessed by other threads.


Process is maintained by the program contains resources (static resources), such as: Address space, open file handle set, file system status, signal processing handler, and so on;


The thread maintains the running related resources (dynamic resources), such as: run stack, scheduling related control information, signal set to be processed, etc.;


threads and processes have advantages and disadvantages in use : the overhead of thread execution is small but not conducive to the management and protection of resources, while the process is the opposite.


Reference: Iteye


Linux system Programming--differences and linkages between processes and threads

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.