1

Lets say I have two processes, process A and process B

When the system is in Process A, CPU generates a virtual address let's say 0x800000. And the it switches to process B via context switch, the CPU also generates a same virtual address 0x800000. so if we write something to the page, how OS know it should be a page in Process B need to be modified rather than Process A?

  • Possible duplicate of [Virtual Memory and Physical Memory](https://stackoverflow.com/q/31524452/608639), [What are the differences between virtual memory and physical memory?](https://stackoverflow.com/q/14347206/608639), etc – jww Nov 27 '18 at 09:00

1 Answers1

1

It is logical memory translation that separates processes; not virtual memory.

Processes see logical memory addresses and have no access to the underlying physical memory. Each process has tables that tell the CPU how to translate logical addresses to physical addresses. The operating system maintains these tables.

The location the tables are identified using protected hardware registers. When Process A switches out and Process B switches in, the operating system (assisted by the underlying hardware) changes the value of the registers so that B's tables are used. After that, the logical address 0X800000 no longer refers to "A"s physical memory location and instead points to "B"'s.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • you mean it is the page table that control which virtual process to use by changing page table base register? –  Nov 27 '18 at 01:19
  • 1
    The process context is defined by a number of register values. These include the general registers that the program has direct access to an protected system registers. It is not a single register that changes with the process but multiple registers. One or more of these registers will specify the page table(s). The number of registers involved is entirely system specific. – user3344003 Nov 27 '18 at 01:24
  • thank you I see. And could you also have a look at this question, please? https://stackoverflow.com/questions/53492168/executable-object-files-and-virtual-memory –  Nov 27 '18 at 03:10