Operating system 为什么指针p在不同的进程中具有相同的值?

Operating system 为什么指针p在不同的进程中具有相同的值?,operating-system,Operating System,当我读OSTEP时,我遇到了一个问题 1 #include <unistd.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include "common.h" 5 6 int 7 main(int argc, char *argv[]) 8 { 9 int *p = malloc(sizeof(int)); // a1 10 assert(p != NULL); 11

当我读OSTEP时,我遇到了一个问题

1 #include <unistd.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "common.h"
5
6 int
7 main(int argc, char *argv[])
8 {
9      int *p = malloc(sizeof(int)); // a1
10     assert(p != NULL);
11     printf("(%d) address pointed to by p: %p\n",
12     getpid(), p); // a2
13     *p = 0; // a3
14     while (1) {
15         Spin(1);
16         *p = *p + 1;
17         printf("(%d) p: %d\n", getpid(), *p); // a4
18     }
19     return 0;
20 }
结果是

[1] 24113
[2] 24114
(24113) address pointed to by p: 0x200000
(24114) address pointed to by p: 0x200000
(24113) p: 1
(24114) p: 1
(24114) p: 2
(24113) p: 2
(24113) p: 3
(24114) p: 3
(24113) p: 4
(24114) p: 4
...
因此,程序似乎处于不同的进程中,并且具有不同的地址空间。 指针p在不同的进程中应该有不同的值,但为什么它是相同的呢? 谢谢大家!

[1] 24113
[2] 24114
(24113) address pointed to by p: 0x200000
(24114) address pointed to by p: 0x200000
(24113) p: 1
(24114) p: 1
(24114) p: 2
(24113) p: 2
(24113) p: 3
(24114) p: 3
(24113) p: 4
(24114) p: 4
...