Performance Test--1 Server Monitoring--1.1 Process and Thread

Definition of process and thread

**Process:** A process is a program with certain independent functions. Regarding a running activity on a certain data set, it is an independent unit for resource allocation and scheduling by the system. For example: running top under linux, top is an
independent Process, running qq under windows, qq is an independent process
**Thread: **Thread is an entity of a process, the basic unit of cpu scheduling and allocation, it is a basic unit smaller than a process that can run independently, a thread Basically do not own system resources, only have a little essential resources in operation. One thread can create and revoke another thread. **
Summary:** A process can have multiple threads, and threads can interact with each other Operation, threads do not own resources, but are declared and occupied by processes.
insert image description here
The difference between processes and threads:
1. A process can have multiple threads, while a thread can only belong to one process.
2. A thread is the smallest unit of work for a process.
3. A process will allocate an address space, and the address space is not shared between processes.
4. Different threads under the same process share the address space of the parent process.
5. Threads need to be synchronized during execution. Threads of different processes
6. Threads are the basic unit of scheduling and allocation, and processes are the basic unit of resources. ( Core)

Personal summary:
Processes are equivalent to warehouses, threads are equivalent to workers, each warehouse has independent addresses and resources (tools), each warehouse can have multiple workers, and workers can share resources in their own warehouses. Multiple workers ( When multithreading) work, messages should be able to synchronize with each other.

Advantages and disadvantages of processes and threads

Advantages of the process:
1. Each process is independent of each other, does not affect the stability of the main program, and the crash of the sub-process does not affect other processes. (For example, the crash of word does not affect the operation of qq) 2. By increasing the CPU, the performance can
be
expanded3 . Can minimize the impact of thread locking and unlocking, greatly improving performance

Disadvantages of the process:
1. The logic control is complex and needs to interact with the main program.
2. The overhead of multi-process scheduling is high

Advantages of threads:
1. The logic and control methods are simple.
2. All threads can directly share memory and variables.
3. The total resources consumed by the thread method are less than that of the process method.

Disadvantages of threads:
1. Each thread shares the address space with the main program, and the maximum memory address is limited.
2. The synchronization and locking between threads is not easy to control.
3. The crash of a thread may affect the stability of the entire program.

Guess you like

Origin blog.csdn.net/weixin_44934430/article/details/118681323