Relationship between processes, threads, and application domains

Source: Internet
Author: User

A process is an application running in the system. A thread is the basic unit for the system to allocate processor time resources, or a unit that is executed independently within the process. For the operating system, the scheduling unit is a thread. A process includes at least one thread, which is usually called as the main thread. A process starts from the execution of the main thread and creates one or more additional threads.
What is the difference between a process and a thread? A process is an instance of the execution program. For example, when you run the upload program (nodepad.exe, you create a code used to form notepad.exe and the process that needs to call the dynamic link library. Each process runs in a dedicated and protected address space. Therefore, if you run two copies of notepad at the same time, the data used by the program is independent of each other in the respective instances. The data opened by the second instance of the program cannot be seen in a copy of notepad.
The sandbox is used as an example to describe. A process is like a sandbox. The thread is like a child in the sandbox. The children ran around in the sandbox, and may drag the sand into the eyes of other children. They would kick each other or bite each other. However, the difference between these sandboxes is that each sandbox is completely closed by walls and ceilings. No matter how hard the children in the sandbox are, they will not affect other children in other sandboxes. Therefore, each process is like a protected sandbox. No one can go in or out without permission.
In fact, the thread runs but the process does not run. The only way for two processes to obtain dedicated data or memory is to share the memory block through the Protocol. This is a collaboration policy. Next let's analyze the process tab in the task manager.
The process here refers to a series of processes that are identified by the executable program instances they run. This is why the ing name is given in the first column of the Process tab. Note that there is no process name column. A process does not have a ing name independent of the instance to which it belongs. In other words, if you run five Beibei, you will see five processes called notepad.exe. How are they different from each other? One way is through their process ID, because each process has its unique encoding. The process ID is generated by Windows NT or Windows 2000 and can be used cyclically. Therefore, process IDs will not be larger and larger, and they can be recycled. The third column is the percentage of CPU time occupied by the threads in the process. It is not the number of the CPU, but the percentage of CPU time occupied by the process. At this time, my system is basically idle. Although the system seems to use only a small amount of CPU time every second or so, the idle process of the system still consumes about 99% of the CPU time.
The fourth column shows the CPU time, which is the hour, minute, And seconds occupied by threads in the process. Please note that I use the word "Occupy" for threads in the process. This does not necessarily mean that it is the total CPU time consumed by the process, because, as we will see later, the NT timing method is that when a specific clock interval is triggered, no matter who happens to be in the current thread, it will be calculated within the CPU cycle. Generally, the clock runs at 10 milliseconds in most NT systems. The heart beats every 10 ms of NT. Some driver code snippets run and show who is the current thread. Let's keep the last 10 milliseconds of CPU time in its account. Therefore, if a thread starts to run and is finished after 8 ms of continuous running, then the second thread starts to run and lasts for 2 ms, the clock is triggered, please guess which thread the entire 10 ms clock cycle is recorded in? The answer is the second thread. Therefore, there are some inherent inaccuracies in NT, and NT timing is in this way. The actual situation is also true. In most 32-bit operating systems, there is an interval-Based Timing mechanism. Remember this, because sometimes when you observe the total CPU usage of a thread, it may appear although the thread may have been running for more than 100,000 times, however, the CPU usage may be zero or very short-lived, so the above explanation is the reason. The above is the basic information column we can see in the process tab of the task manager.

 

 

A process is a management unit that manages multiple threads of an application. There is a default main thread, and other threads are derived from other threads. Once a thread is created, the main thread cannot interfere with it. The destruction of a thread in. Net terminates the thread by throwing an exception.

In. before the emergence of net, only one application can be run under a process. After the emergence of net, multiple applications can be run under a process, this is because of the emergence of application domains.

Previously, process boundaries were used to isolate applications running on the same computer. Each application is loaded into a separate process, which isolates the application from other applications running on the same computer.

The reason for isolating these applications is that the memory address is related to the process. In the target process, the memory pointer from one process to another cannot be used in any meaningful way. In addition, you cannot directly call between two processes. You must replace it with a proxy, which provides a certain degree of indirect.

The application domain provides secure and universal processing units, which can be used by the Common Language Runtime Library to provide isolation between applications. You can run several application domains in a single process with the same isolation level (in a separate process, this does not cause additional overhead for inter-process calls or inter-process switching. The ability to run multiple applications within a process significantly enhances the scalability of the server.

Isolating applications is also important for application security. For example, you can run several web application controls in a single browser process, and make these controls inaccessible to each other's data and resources.

Application domain isolation has the following advantages:

Errors in one application do not affect other applications. Because the type-safe code does not cause memory errors, you can use the application domain to ensure that the code running in one domain does not affect other applications in the process.
A single application can be stopped without stopping the entire process. The application domain allows you to uninstall code running in a single application.
Application domains form the isolation, uninstallation, and security boundaries of managed code. A thread is the operating system structure used by the Common Language Runtime Library to execute code. At runtime, all managed code is loaded into an application domain and run by a specific operating system thread.

There is no one-to-one correlation between application domains and threads. At any given time, several threads can be executed in a single application domain, and the specific threads are not limited to a single application domain. That is to say, threads can freely span application domain boundaries, without creating new threads for each application domain.

At any given time, each line is executed in an application domain. The Runtime Library tracks which threads are running in which application domains.

 

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.