Reputation: 522
[linux 3.2] I am wondering if it is possible to find out the memory location of a file opened in a program. Suppose I have the code below in a.cpp which compiles to a.out:
FILE *f = fopen("myfile", "r");
Will the content be mapped into the memory space of a.out? If so, how could I find it(the pages? the range?) out?
Thanks
Upvotes: 3
Views: 456
Reputation: 1491
The structure to which the FILE* points holds some information about the state of the file. The contents are not mapped into program's memory space.
If you want to map file contents into the memory space you have to use mmap() function. This will give you a pointer to a memory region in the process's logical memory space. This memory region will hold the contents of the file.
Upvotes: 4