在虚拟内存中,两个不同的进程可以有相同的地址吗? [英] In virtual memory, can two different processes have the same address?

查看:88
本文介绍了在虚拟内存中,两个不同的进程可以有相同的地址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在一个网站上找到的一个面试问题,问题是:在虚拟内存中,两个不同的进程可以有相同的地址吗?当你回答否"是正确的,一个进程如何访问另一个进程'内存,例如调试器可以访问变量并在调试时更改它们?"

This is an interview question I found in a website, the questions says: "In virtual memory, can two different processes have the same address? When you answer "No" which is correct, how one process can access another process' memory, for example the debugger can access the variables and change them while debugging?"

我的理解是:

  1. 2 diff 进程可以有相同的虚拟内存地址.这是因为每个进程都有自己的页表.每个进程都认为它是 32 位机器上的 4Gb 内存.所以 P1 和 P2 都可以访问地址 0xabcdef - 但物理内存位置可能不同.这不是吗?

  1. 2 diff process can have same virtual memory address. This is because each process has its own page table. Each process thinks it as 4Gb memory on a 32-bit machine. So both P1 and P2 can access address 0xabcdef - but the physical memory location might be different. Isnt this right ?

调试器的工作原理相同——两个进程可以访问同一个地址.因此它可以即时修改变量等.

The debugger works on the same principle - 2 processes can access the same address. So it can modify variables etc on the fly.

推荐答案

1)

  • 同时使用相同的物理内存地址:否
  • 同时使用相同的虚拟内存地址:是(每个都映射到不同的物理地址或交换空间)

2) 我认为调试器不会直接访问被调试的其他进程,而是与被调试进程中的运行时通信以进行更改.

2) I think the debuggers don't access directly the other process debugged but communicates with the runtime in the debugged process to do that changes.

也就是说,如果您有权限,操作系统或处理器指令可能会提供对他人内存访问的访问/修改.这并不意味着它具有相同的地址,它只是说进程 1 可以说在进程 2 中访问内存 @address1".有人(处理器/操作系统/运行时)将为进程 1 执行此操作.

That said, maybe the OS or processor instructions provide access/modify to other's memory access if you have the right. That doesn't mean it has the SAME address, it only says process 1 can say "access memory @address1 in Process2". Someone (processor / OS / runtime) will do that for process 1.

这篇关于在虚拟内存中,两个不同的进程可以有相同的地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆