- #include <stdio.h> ??
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h> ??
- ??
- void ? Main ()??
- {??
- ???? char "Hello"
- ??
- ???? Pid_t?pid=fork ();??
- ??
- ???? if (pid==0)??
- ???? {??
- ???????? str[0]=' B ';? ?
- ???????? printf ( "Sub-process str=%s\n" ,str);??
- ???????? printf ( "The first address that Str points to in the child process:%x\n" int
- ????}??
- ???? Else ??
- ???? {??
- ???????? Sleep (1);??
- ???????? printf ( "Parent Process str=%s\n" ,str);??
- ???????? printf ( "The first address that Str points to in the parent process:%x\n" int
- ????}??
- }??
Str=bello in child process
the first address that Str points to in a child process: BFDBFC06?? the virtual address is taken here.
Str=hello in parent process
the first address that Str points to in the parent process: BFDBFC06? The virtual address is taken here.
Explanation: Using the "Write copy technique", the child process did not change the value of the data segment when it was first fork. The child process and the parent process are all code-shared, with the same physical address. The same virtual address,
When a child process changes a variable, the variable is actually copied to the child process and has its own physical address. But the virtual address is still the same, two of the same virtual address points to a different physical address.
So the above answer appears.
is the virtual address here the same? But the physical address is different.
The fork () function of Linux specifically explains what the child process replicates the parent process