mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 14:54:05 -06:00
vault backup: 2022-10-12 09:44:42
This commit is contained in:
parent
8378be5c81
commit
0bc4c76bd8
@ -10,6 +10,30 @@ tags:
|
|||||||

|

|
||||||
|
|
||||||
Can't assume all variables are initally zero.
|
Can't assume all variables are initally zero.
|
||||||
|
OS decide which process maps who which physical address
|
||||||
|
|
||||||
|
memory mapping `mmap` is a family of system calls:
|
||||||
|
- allow two processes to share some region of their memory space.
|
||||||
|
- achieved by creating a memory region that can be shared by other processes
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
shared memory by two processes mapping to the same file or using fork() after mmap()
|
||||||
|
``` c
|
||||||
|
random_fd = open("/home/hzy/test/zero", O_RDWR);
|
||||||
|
ptr = mmap(NULL, 10240, PROT_READ|PROT_WRITE,
|
||||||
|
MAP_SHARED | MAP_FILE, random_fd, 0);
|
||||||
|
```
|
||||||
|
|
||||||
|
private mapping is often ysed to set up new memory sections.
|
||||||
|
``` c
|
||||||
|
fd = open("mmap_test_file", O_RDWR); p
|
||||||
|
tr = mmap(NULL, 10240, PROT_READ|PROT_WRITE,
|
||||||
|
MAP_PRIVATE|MAP_FILE, fd, 0);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
# Threads
|
# Threads
|
||||||
Lightweight process - shares everything except the stack
|
Lightweight process - shares everything except the stack
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user