I have just started learning about virtual memory and I don't understand if I can see the memory that I have allocated with mmap(). The 2 show_maps() print the same text. Shouldn't I also see the allocated memory from mmap() in the second show_maps() and if not is there a way to see it?
#define MAPS_PATH "/proc/self/maps" #define LINELEN 256 void show_maps(void) { FILE *f; char line[LINELEN]; f = fopen(MAPS_PATH, "r"); if (!f) { printf("Cannot open " MAPS_PATH ": %s\n", strerror(errno)); return; } printf("\nVirtual Memory Map of process [%ld]:\n", (long)getpid()); while (fgets(line, LINELEN, f) != NULL) { printf("%s", line); } printf("--------------------------------------------------------\n\n"); if (0 != fclose(f)) perror("fclose(" MAPS_PATH ")"); } int main(void) { pid_t mypid; int fd = -1; uint64_t *pa; mypid = getpid(); show_maps(); pa=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); show_maps(); }