Net developers should know

Source: Internet
Author: User

What is the difference between a thread and a process?

A thread is a processing module smaller than a process.
Processes and threads are the basic units for running programs that the operating system understands. The system uses this basic unit to realize the system's concurrency for applications. The difference between a process and a thread is:

In short, a program has at least one process, and a process has at least one thread.
The thread division scale is smaller than the process, making the multi-thread program highly concurrent.
In addition, the process has independent memory units during execution, and multiple threads share the memory, which greatly improves the program running efficiency.
The execution process of a thread is different from that of a process. Each Independent thread has a program running entry, sequence execution sequence, and program exit. But the thread cannot be executed independently. It must exist in the application and the application provides multiple thread execution control.
Logically, multithreading means that multiple execution parts in an application can be executed simultaneously. However, the operating system does not view multiple threads as multiple independent applications to implement process scheduling, management, and resource allocation. This is an important difference between processes and threads.

A process is a running activity of a program with certain independent functions. A process is an independent unit for the system to allocate and schedule resources.
A thread is an entity of a process. It is the basic unit for CPU scheduling and scheduling. It is smaller than a process and can run independently. the thread itself basically does not have system resources, and only has a few resources (such as program counters, a set of registers and stacks) that are essential for running ), however, it can share all resources of a process with other threads of the same process.
One thread can create and cancel another thread, and multiple threads in the same process can be concurrently executed.

 

Thread Introduction: for example, if a Web server processes webpage access requests from different users concurrently, you can create a parent process and multiple child processes to process the requests, however, creating a process consumes a lot of system overhead and resources. Except that these different user sub-processes involve context switching during execution. Context switching is a complex process. Therefore, in order to reduce the overhead of process switching and creation, improve execution efficiency and save resources, the concept of "thread" is introduced in the operating system.

The role and definition of a process: a process is proposed to improve the CPU execution efficiency and reduce the CPU idling caused by program waits and the waste of other computer software and hardware resources. A process is a basic unit for the execution process of a program required to complete a user task and allocate resources to it. It is an execution activity of a program segment with independent functions on a dataset.

Differences between threads and processes:

1. A thread is a part of a process. Therefore, a thread is sometimes called a lightweight or lightweight process.

2. A process without threads can be considered as a single thread. If a process has multiple processes, the execution process of the process is not a line (thread, it is done by multiple threads.

3. When running, the system allocates different memory regions for each process, but does not allocate memory for the thread (the resources used by the thread are the resources of the process to which it belongs ), thread groups can only share resources. That is to say, out of the CPU (the thread occupies CPU resources when running), the allocation of hardware and software resources inside the computer is irrelevant to the thread, and the thread can only share the resources of the process to which it belongs.

4. Similar to the process control table PCB, the thread also has its own control table TCB, but the thread state stored in TCB is much less than that in the PCB table.

5. A process is a basic unit for allocating all resources of the system. It has a complete virtual space address and does not depend on threads but exists independently.

Differences between processes and programs:

A program is a set of commands. It is a static entity and has no meaning of execution. A process is a dynamic entity with its own lifecycle. Generally, a process must correspond to only one program, but one program may have multiple processes or none of them. In addition, the process also has concurrency and interactions. Simply put, a process is a part of a program. A process is generated when the program runs.

Summary:

A thread is a part of a process and a process is a part of a program.

 

What is a Windows service? What is the difference between its lifecycle and the standard EXE program?

 

Windows Service is an application that is mainly used in the server environment and runs for a long time. Such applications do not require user interfaces or any analog output. All user messages are usually recorded in Windows event logs. Windows Service can start at the startup of the operating system and run in the background all the time. You can also start it manually when necessary. We can manage the services in the management tool in a unified manner.

After the system is started, the Windows service does not need to be started after logging on to the page, but the general exe file must be logged on to Windows before it can be started.

 

Windows Service is a program that can be started with the startup of a Windows operating system. It runs in the background and generally does not interact with users. It cannot be run by double-clicking, similar to the Unix daemon processes. It will not stop when the user logs out.

Windows Services are composed of three parts: 1. A service executable file; 2. one Service Control Program (SCP); 3. the Service Control Manager (SCM) is responsible for creating service key values under HKLM \ SYSTEM \ CurrentControlSet \ Services. You can use SCP to control the startup, stop, and suspension of a service. SCP calls the service program through SCM.

Window standard exe executable programs usually have a user interface, Console or GUI, which is usually started or stopped by users.

 

Windows Service is an application running under the specified user (default System) in the windows background. It does not have a standard UI interface and is similar to a standard EXE program, A Windows service is created at the beginning of the service and destroyed at the end of the service. You can also set whether the service is started with the operating system and disabled together. It supports three methods: 1) automatic mode 2) manual mode 3) disabled. When the automatic mode is enabled, the windows service starts automatically after the OS is started, and the manual mode must start the service manually. If the disabled mode is disabled, the service cannot be started. In addition, standard EXE uses the currently logged-on user by default, while windows uses the System user by default, which requires special attention when accessing System resources.

 

 

What is the maximum memory size that a single process can access on Windows? Is it the same as the maximum virtual memory of the system? What is the impact on system design?

 

On 32-bit Windows, the maximum memory size that a single process can access is 4 GB. The operating system needs to allocate 2 GB space to the system core, therefore, the maximum memory used by a user program process is 2 GB.

Not necessarily the same. The maximum memory size accessible to 32-bit operating system processes is 4 GB, which 4 GB includes virtual memory, the maximum amount of memory that a process can access is 4 GB. Therefore, the process's memory access volume is irrelevant to the virtual memory when the physical memory is greater than or equal to 4 GB. When the physical memory is less than 4 GB, the amount of memory accessed by the process increases with the increase of virtual memory until 4 GB

 

Windows uses a virtual addressing system. The system maps the available memory addresses of the program to the actual addresses in the hardware memory. These tasks are fully managed in the Windows background, the actual result is that each process on a 32-bit processor can use 4 GB of memory-no matter how much hard disk space on the computer (this value will be larger on a 64-bit processor ). This 4 GB memory actually contains all the parts of the program-including executable code, all the dll loaded by the code, and the content of all the variables used when the program is running. This 4 GB memory is called virtual address space or virtual memory.

 

What is the difference between EXE and DLL?

EXE is an executable file. You can double-click it to run it, while DLL is a dynamic link library file, that is, it cannot run on its own, it can be run only when other functions of a program are run. For example, if you want to upgrade QQ, it will run the upgraded DLL file in QQ.

 

EXE is an application with a program entry (Main) that can be directly executed by end users. As it starts the system, it will generate a corresponding process.

DLL is a dynamic link library that does not include the program execution entry and cannot be directly executed by end users. It must be appended to an existing process to run.

However, both are based on the PE format. during runtime, the image on the disk is loaded into the memory or shared space of the caller for execution, which contains the program data information, but the EXE also contains the program code information.

DLL can be shared by multiple programs, while EXE cannot. It can only be executed separately.

 

What is a strong type and what is a weak type? Which one is better? Why?

 

A weak language allows multiple types of memory. For example, you can directly add integer and character variables. C and C ++ are static languages and weak languages. Perl and PHP are dynamic languages, but also weak languages.

Before forced type conversion, two variables of different types cannot operate on each other. Java, C #, and Python are both strongly typed languages.

The language you want to use depends on your needs. Writing simple small applications and using a weak type language can save a lot of code and improve development efficiency. For large projects, using strong languages may be more standardized and reliable than using weak types.

 

A strong type means that data in the memory must be converted to a type. Otherwise, data cannot be used. For a weak type, no program conversion is required. during runtime, the system automatically processes the data directly.

Advantages of using strong types: supports smart input prompts, detects potential running problems during compilation, and avoids data inconsistency in interfaces, in addition, the use of strong types can speed up program development and program running.

 

What is PID? How to use the system in troubleshooting?

PID is the globally unique identifier of a system process. In case of system faults, you can locate the corresponding process based on the PID and find the corresponding program.

PID = Process Identifier, which is a globally unique integer used to identify a Process. In a multitasking system, it can be used to diagnose errors in the system.

 

How many processes can a single TCP/IP Port listen?

There may be only one. If you need to create another TCP/IP listener, you must create another different port.

 

What is GAC? What problems does it solve?

Gloal Assembly Cache: global application Assembly Cache. It solves the problem that several programs share an assembly. You no longer need to copy the shared assembly to the application directory. In fact, this principle is very simple ,. when a. net application is loaded, it first checks the global application Assembly Cache. If yes, it can be used directly without searching in the application directory.

 

 

Each computer on which CLR (Common Language Runtime) is located has a Global Assembly Cache (GAC ). The Assembly deployed on GAC must have a strong name. A development tool provided by. net framework sdk named "Global Assembly Cache tool" (Gacutil.exe) that can deploy an Assembly to GAC. GAC stores the specified assembly for sharing among multiple applications on the computer. It also provides us with solutions to the "DLL hell" issue.

Explanation on Baidu Encyclopedia:

GAC stands for Global Assembly Cache.
The role is to store some public assemblies that are used by many programs, such as System. Data and System. Windows. Forms. In this way, many programs can obtain the Assembly from the GAC without copying all the Assembly to the execution directory of the application. For example, if there is no GAC, it is inevitable that the path of each WinForm must be from C: \ WINDOWS \ Microsoft. NET \ Framework \ v1.0.3705 copy a copy of the System. windows. forms. dll, which is obviously easier to use from the GAC, but also conducive to the Assembly upgrade and version control.

In addition to the System default Assembly placed in GAC, such as System. Windows. Forms, we can also add our own Assembly:
1) create a strong-name Assembly, such as ToolbarComponent. dll.
2) Run gacutil-I ToolbarComponent. dll and add this Assembly to GAC.
3) dynamic loading in the program:
System. Reflection. Assembly ass = Assembly. Load ("ToolbarComponent, Version = 1.0.934.20434, Culture = neutral, PublicKeyToken = 65f45658c8d3167f ");
MessageBox. Show ("Is the assembly loaded from GAC? "+ Ass. GlobalAssemblyCache );
In the above program, ToolbarComponent is loaded from GAC rather than from the dll file under the program running directory. The ToolbarComponent. dll program can run normally without being placed in the program directory. In addition, parameters in Assembly. Load () can be found through "gacutil-l.

In addition, the Assembly in GAC must be strong-name. The steps for creating an Assembly with strong-name are as follows:
A) Run "sn-k keyPair. snk" on the command line to create a key file. Sn.exe is also a tool attached to. NET.
B) modify the "AssemblyInfo. cs" file in VS. NET:
[Assembly: AssemblyDelaySign (false)]
[Assembly: AssemblyKeyFile ("... \ .. \ keyPair. snk")]
C) compile the project to get a strong-name Assembly.

The following describes GAC in MSDN:
1) Assembly Cache Viewer (Shfusion. dll)
2) Global Assembly Cache

. NET Framework comes with some GAC-related tools, including:
1)Gacutil.exe, a command line tool used to browse, add, and delete an Assembly in GAC
2ngen.exe is also a command line tool used to create Native Image in GAC
3. mscorcfg.msc, an mmc, You can graphically complete the main functions of gacutil.exe.

 

----- This article is organized by watching the cloud. If you have any questions, we welcome your comments.

Thank you @ Wu Feng-for "How many processes can be listened on a single TCP/IP Port?

There may be only one. If you need to create another TCP/IP listener, you must set up another different port!

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.