Home >System Tutorial >LINUX >What is a lightweight process? This article will give you a deeper understanding

What is a lightweight process? This article will give you a deeper understanding

王林
王林Original
2024-07-24 09:38:191139browse

What is a lightweight process? This article will give you a deeper understanding

1. What are lightweight processes

Before understanding lightweight processes, we first need processes and threads. We all know that a process is essentially a collection of pcb, virtual address space, page table and code data, that is, a collection of kernel data + code data. It looks like this from a user's perspective. From a CPU perspective, a process is the unit that allocates system resources. As for the thread, it is executed within the process and is the basic unit of operating system calls. Although the CPU does not know which processes or threads linux process and thread kernel when scheduling, it only recognizes the pcb structure. That is, the Linux version of execution flow, and this thing is a thread. Different operating systems may use different structural forms to implement threads. Under Linux, the structure of threads and the structure of processes are completely consistent. This causes the video memory of PCB under Linux to be larger than or equal to other operating systems. This causes the process volume of Linux to be larger than that of other operating systems. These processes are lightweight processes. The main difference between lightweight processes (LWP) and normal processes is that LWPs share the same address space and other resources such as open files, etc. Because some resources are shared, this process is considered lightweight compared to other ordinary processes and hence the name lightweight process.

内核进程和内核线程_linux内核多线程_linux进程与线程 内核

linux内核多线程_内核进程和内核线程_linux进程与线程 内核

2. Lightweight process id and process id

linux内核多线程_linux进程与线程 内核_内核进程和内核线程

First of all, it is certain that the process ID is definitely not the ID of a lightweight process. Only when a process has only a single execution flow, and at this time the process has only one main thread, the process ID and lightweight process ID at this time are also It's just lwp that's the same. In other cases, a thread has an lwplinux process and thread kernel, and the CPU also schedules lwp when scheduling.

内核进程和内核线程_linux内核多线程_linux进程与线程 内核

3. The relationship between LWP and threads created by pthread_create

linux进程与线程 内核_内核进程和内核线程_linux内核多线程

When the program calls the pthread_create() function, it creates a new LWP. This new LWP is used to implement the newly created thread and share the resources of the same process with other threads. Therefore, we can regard the thread created by pthread_create as a kind of LWP created in the program.

In other words, LWP corresponds to the thread created by pthread_create, and the thread created by pthread_create is equivalent to the LWP in the system.

The above is the detailed content of What is a lightweight process? This article will give you a deeper understanding. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn