About processes and threads

xiaoxiao2021-03-06  37

Process: It is an instance of execution of the program; the program is always running in a context of a process. Each process has its own independent address space. Each time the user enters an executable name through the Shell, run a program or double-click on Windows to double-click a file to perform files, the system creates a new process.

Program: It is a collection of code and data; the program can be existing on the disk as the target module, or as a segment exists in the address space.

Context: It is composed of the status required to run correctly. This status includes program code and data stored in the memory, its stack, its general purpose destination register content, program counter (PC), environment variable, and collection of open file descriptors.

The advantage of the process: Each process has its own independent address space, so a process will not carefully cover the virtual memory of another process. Process-based multi-tasking features are characterized by allowing your computer to run two or more programs at the same time, and the process shares the CPU time, the system is responsible for the switching.

Disadvantages of the process: The independent address space is difficult to share status information. In addition, the switching and communication overhead between threads is very large.

Thread: A thread is a logic stream running in a process context. Each thread has its own thread context, including unique integer thread ID, stack, stack pointer, program counter, universal destination register. All threads running in a process share the entire virtual address space of the process.

Thread execution model: Each process starts a single thread, called "main thread", creates a peer thread at a time main thread. If the main thread stop system is switched to its peer thread.

Thread Advantages: The context of the thread is more than the context of the context of the process, so the context switching of the thread is safer than the context of the process. Threads are not organized in accordance with strict parental relations. And a process-related thread form a peer-to-peer thread pool, one thread can kill any peer thread. Each thread can read and write the same shared data.

Thread Disadvantages: Since the data sharing will bring synchronous problems, it will lead to the generation of deadlocks. Death locks cannot be resolved on the language level, requiring a good design of the program to avoid dead locks.

Reference: << Computer Systems, a Programmer's Perspective >> << Java2 Reference Daquan, 4th Edition >>

Note: This article is just a brief introduction, and it is needed to add in detail, or change the error.

转载请注明原文地址:https://www.9cbs.com/read-65716.html

New Post(0)