Can OS map same physical page to different processes page tables? Can processes share same physical page? If they share same page, can one process can corrupt other processes data and code?
Asked
Active
Viewed 1,286 times
1 Answers
0
Yes. Specifically with reference to Linux, when a thread (task) is created, it may share the same memory location with other thread (task).
The clone
system call has a special flag CLONE_VM
in Linux, and it specifically for sharing of memory (which is after all deep down a physical page).
If they share same page, can one process can corrupt other processes data and code?
It is the responsibility of the programmer to take care of this. One of the ways to handle this is using mutex.

Syed Waris
- 1,056
- 1
- 11
- 16
-
You typically have the kernel memory mapped in multiple processes' address spaces from the get go. – Alexey Frunze Feb 21 '19 at 06:00
-
Can you please elaborate more? Are you saying the kernel memory is shared with every process from the start? Well yes, that is correct and that is another example – Syed Waris Feb 21 '19 at 06:07
-
I know that threads share data, code and files within the process. But I am asking that can two PROCESSES share same page? – anandthegreat Feb 21 '19 at 07:01
-
@anandthegreat In Linux threads and processes are treated as same - they are called task. And yes in other OSs (other than Linux), threads can share the same page. The answer is YES. – Syed Waris Feb 21 '19 at 07:04
-
@Syed.Waris Usually the kernel code and data is present in all address spaces/processes. Why? How would you handle in the kernel exceptions generated by processes and hardware interrupts if the kernel isn't there? There's no kernel that loads the kernel. – Alexey Frunze Feb 21 '19 at 08:50