Talk C together (133rd back: C language instance-memory details during process creation)
Hello, everyone. In the previous session, we talked about the process and thread examples from the memory perspective. The example here is the memory details during process creation. When you leave the rest of your time, your words will go right. Let's talk C chestnuts together!
As we all know, the fork function can be used to create a new process. Today, let's talk about the memory details when using this function to create a process. We will focus on four partitions in the memory layout.
1. when fork is used in the parent process, a new process is created, which is called a sub-process. The sub-process has its own memory space. 2. there is no code zone in the memory space of the child process. The child process and the parent process share the code zone. 3. the sub-process memory space has its own data zone, heap zone, and stack zone, and the content in these areas is a copy of the content in the parent process area; 4. the replicas mentioned above indicate that the content in the parent and child processes is the same, but the child process does not directly copy the content from the parent process, but is a bit like a pointer in the C language, sub-processes point to the memory of the parent process through the "Pointer", so their content is the same; 5. the sub-process does not directly copy the content in the memory of the parent process because it consumes time and space and affects the efficiency of Process Creation. 6. when the content in the sub-process memory space is modified, the sub-process begins to copy the content of the parent process memory space. At this time, the sub-process memory space content completely belongs to itself, this change is called the copy on write technology (copy on write); 7. because the content in the sub-process memory belongs to itself, modifying the content in the sub-process memory does not affect the content in the parent process memory. This is an example in the previous chapter, I will not give an example here; 8. executing the execve series functions will also trigger write-time replication. For the execve series functions, we will introduce them later in the following chapter; 9. the replication technology at write time can reduce unnecessary memory replication operations and improve the efficiency of Process Creation;
We listed the memory details during process creation step by step, hoping to help you understand the memory details during Process Creation in detail.
Let's talk about the example of "memory details during Process Creation. I want to know what examples will be provided later, and I will try again.