In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
My understanding is that a process is an application running in the system; once a program is running, it is a process, or more professionally speaking: a process is an instance of program execution, and a thread is an entity of a process.
Process-the smallest unit of resource allocation, thread-the smallest unit of program execution.
The differences between threaded processes are reflected in several aspects:
0: because a process has independent stack space and data segments, every time a new process is started, it must be assigned an independent address space, and a large number of data tables must be established to maintain its code, stack and data segments. This is very "extravagant" for multi-processes, the system overhead is relatively large, while threads are different, threads have independent stack space, but share data segments. They use the same address space with each other, share most of the data, are more frugal than the process, have less overhead, and switch faster and more efficiently than the process, but it is precisely because of the independence between processes that makes the process more secure, and because the process has an independent address space, after a process crashes, it will not affect other processes in protected mode. A thread is just a different execution path in a process. The death of one thread equals the death of the whole process.
1: reflected in the communication mechanism, precisely because the processes do not interfere with each other and are independent of each other, the communication mechanism of the process is relatively complex, such as pipes, signals, message queues, shared memory, sockets and other communication mechanisms. the thread communication mechanism is very convenient because it shares data segments.
2: all threads belonging to the same process share all resources of that process, including file descriptors. Different processes are independent of each other.
3: threads are also called lightweight processes. Processes have process control blocks, and threads have thread control blocks.
4: a thread must belong to only one process, and a process can have multiple threads and at least one thread
5: reflected in the program structure, to give a simple and easy-to-understand list: when we use the process, we involuntarily use if else nesting to judge pid, which makes the program structure tedious, but when we use threads, we can basically get rid of it, of course, the internal execution function unit of the program still needs to be used, so threads are of great help to the improvement of program structure.
The choice of process and thread depends on the following points:
0: priority threads for destruction need to be created frequently; because it is expensive for a process to create and destroy a process.
1: thread switching is fast, so using threads when you need a lot of computation, switching frequently, and using threads for time-consuming operations can improve the response of the application.
2: because threads are more dominant in the efficiency of CPU systems, it may be necessary to develop to multi-machine distributed processes and multi-core distributed threads.
3: use threads in parallel operations, such as server-side concurrent threads of Cpuma S, to respond to user requests.
4: when you need more stability and security, it is suitable to select a process; when you need speed, it is better to select a thread.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.