Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The difference between process and thread

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

First, a process is a running activity of a program with a certain independent function on a certain data set, and a process is an independent unit of resource allocation and scheduling in the system.

A thread is an entity of a process and the basic unit of CPU scheduling and dispatching. It is a smaller basic unit that can run independently than a process. The thread basically does not own the system resources, but only has some essential resources (such as program counters, a set of registers and stacks), but it can share all the resources owned by the process with other threads belonging to the same process.

One thread can create and undo another thread; multiple threads in the same process can execute concurrently

Second: processes and threads are the basic units of program running experienced by the operating system, and the system uses this basic unit to realize the concurrency of the application. 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 division scale of threads is smaller than that of processes, which makes multithreaded programs have high concurrency.

In addition, the process has an independent memory unit during execution, and multiple threads share memory, which greatly improves the running efficiency of the program.

There is a difference between a thread and a process during execution. Each independent thread has an entrance to the program, a sequential execution sequence, and an exit to the program. However, threads cannot execute independently and must be stored in the application, which provides multiple thread execution control.

From a logical point of view, the significance of multithreading is that there are multiple execution parts in an application that can be executed at the same time. However, the operating system does not regard multiple threads as multiple independent applications to achieve process scheduling and management and resource allocation. This is the important difference between processes and threads.

Third, the coexistence of multi-threads in applications is a basic feature and an important symbol of modern operating systems.

. Readers who have used the UNIX operating system know that in the UNIX operating system, the execution of each application registers a process flag in the operating system kernel. The operating system schedules the execution of the application and allocates system resources according to the assigned flag, but what's the difference between a process and a thread?

Processes and threads are the basic units of program running experienced by the operating system, and the system uses this basic unit to realize the concurrency of the system to the application. The difference between a process and a thread is:

The division scale of threads is smaller than that of processes, which makes the concurrency of multithreaded programs.

In addition, the process has an independent memory unit during execution, and multiple threads share memory, which greatly improves the running efficiency of the program.

There is a difference between a thread and a process during execution. Each independent thread has an entrance to the program, a sequential execution sequence, and an exit to the program. However, threads cannot execute independently and must be stored in the application, which provides multiple thread execution control.

From a logical point of view, the significance of multithreading is that there are multiple execution parts in an application that can be executed at the same time. However, the operating system does not regard multiple threads as multiple independent applications to achieve process scheduling and management and resource allocation. This is the important difference between processes and threads.

Process (Process) is a concept originally defined to represent the basic execution unit of an application in an in-memory environment in a multi-user, multi-tasking operating system such as Unix. Taking the Unix operating system as an example, the process is the basic component of the Unix operating system environment and the basic unit of system resource allocation. Almost all the work of user management and resource allocation in the Unix operating system is realized through the control of the application process by the operating system.

The source programs written in C, C++, Java and other languages are compiled into executable files by the corresponding compilers and submitted to the computer processor to run. At this point, an application in an executable state is called a process. From the user's point of view, a process is an execution process of an application. From the core point of view of the operating system, the process represents the basic unit of resources such as memory and CPU time slices allocated by the operating system, and it is the running environment for running programs. The difference between the process and the application program is that the application program is stored in the hard disk and other storage space of the computer system as a static file, while the process is a system resource management entity maintained by the operating system under dynamic conditions. The main features of application processes in a multitasking environment include:

The ● process has the initial entry point of the memory unit during execution, and the process always has an independent memory address space during its survival.

The lifetime states of ● processes include create, ready, run, blocking, and death types

● can divide the state of the process into user state and kernel state because of the different running instructions issued to CPU during the execution of the application process. The process in the user mode executes the application instructions, and the application process in the core state executes the operating system instructions.

During the startup of Unix operating system, the system automatically creates system processes such as swapper and init, which are used to manage memory resources and schedule user processes. In the Unix environment, both processes created by the operating system and those created by the application have a unique process identity (PID).

Theory 4: during the execution of an application, there is an initial entry point address of memory space, a code execution sequence during program execution, and a memory exit point address that is used to identify the end of the process. at each point in the process of execution, there are unique processor instructions corresponding to the address of the memory unit.

The Thread defined in the Java language also includes a memory entry point address, an exit point address, and a sequence of code that can be executed sequentially. But the important difference between a process and a thread is that a thread cannot execute alone, it must run in an active application process, so it can be defined that a thread is a sequential code flow with concurrency within the program.

Unix operating system and Microsoft Windows operating system support the concurrent execution of multi-user and multi-process, while Java language supports the concurrent execution of multiple execution threads within the application process. The significance of multithreading is that multiple logical units of an application can be executed concurrently. However, multithreading does not mean that multiple user processes are executing, and the operating system does not allocate independent system resources to each thread as a separate process. A process can create its child process, which has different executable code and data memory space from the parent process. In the process used to represent the application, multiple threads share data memory space, but each thread has a separate execution stack and program execution context (Context).

Based on these differences, threads can also be called lightweight processes (Light Weight Process,LWP). Different threads allow task cooperation and data exchange, which makes it very cheap in terms of computer system resource consumption.

Threads need the support of the operating system, and not all types of computers support multithreaded applications. Java programming language combines thread support with language runtime environment and provides the ability of multi-task concurrent execution. This is like a person in the process of housework, put the clothes in the washing machine to wash automatically, put the rice in the rice cooker, and then start cooking. When the food is ready, the meal is cooked and the clothes are ready.

It is important to note that using multithreading in an application does not increase the data processing power of CPU. Only in the multi-CPU computer or under the network computing architecture, after dividing the Java program into multiple concurrent execution threads, starting multiple threads to run at the same time, and making different threads run in the Java virtual machine based on different processors, can the execution efficiency of the application program be improved.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report