Nishith Goswami
Nishith Goswami

Reputation: 363

Can OS generate same logical Address for two different processes?

As far I know CPU generates logical address for each instruction on run time.

Now this logical address will point to linear or virtual address of the instruction.

Now my questions are ,

1) Can OS generate same logical address for two different processes ?

With reference to "In virtual memory, can two different processes have the same address?" , If two different processes can have same virtual address in that case it is also quit possible that logical addresses can also be the same.

2) Just to clarify my understanding whenever we write a complex C code or simple "hello world" code,Virtual address will be generated at build time (compile->Assemble->link) where logical address will generated by CPU at run time ?

Please clarify my doubts above and also do correct me if I am on wrong way.

Upvotes: 1

Views: 1935

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490178

The logical address and the virtual address are the same thing. The CPU translates from logical/virtual addresses to physical addresses during execution.

As such, yes, it's not just possible but quite common for two processes to use the same virtual addresses. Under a 32-bit OS this happens quite routinely, simply because the address space is fairly constrained, and there's often more physical memory than address space. But to give one well-known example, the traditional load address for Windows executables is 0x400000 (I might have the wrong number of zeros on the end, but you get the idea). That means essentially every process running on Windows would typically be loaded at that same logical/virtual address.

More recently, Windows (like most other OSes) has started to randomize the layout of executable modules in memory. Since most of a 32-bit address space is often in use, this changes the relative placement of the modules (their order in memory) but means many of the same locations are used in different processes (just for different modules in each).

A 64-bit OS has a much larger address space available, so when it's placing modules at random addresses it has many more choices available. That larger number of choices means there's a much smaller chance of the same address happening to be used in more than one process. It's probably still possible, but certainly a lot less likely.

Upvotes: 2

Related Questions