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 threadslinux process and thread kernelwhen 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.
2. Lightweight process id and process id
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.
3. The relationship between LWP and threads created by pthread_create
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!