如果一个程序运行了两个实例,那么有两个进程,这两个进程应该共享代码吧。
但是网上虚拟地址空间的布局中,每个进程都有代码段。那么进程是怎么共享代码的?难道是后来产生的进程的代码段指向前面产生进程的代码段?
巴扎黑2017-04-17 14:44:13
If a program runs two instances, unfortunately, the code of the two programs will not be shared, because the program code is loaded into the memory when the program is running. When the second program is started again, the system cannot The judgment will not determine whether the program is still the original program (if the program is updated or changed), so the program code will still be reloaded into another area of memory.
The shared expression of code should be in 链接库
, especially in 动态链接库
. Because the library is designed to be dynamically linked, the program can determine the memory address where the code is located after running, which allows multiple programs to call the same piece of code.