a lightweight library to parse Linux's /proc/[pid]/maps file, which contains the memory map of a process
A file containing the currently mapped memory regions and their access permissions. See mmap(2) for some further information about memory mappings. #memory map region proc_maps_parser represents a memory region with this C structure.
structprocmaps_struct{
void*addr_start; //< start address of the regionvoid*addr_end; //< end address of the regionunsigned longlength; //< length of the region by bytescharperm[5]; //< permissions rwxp shortis_r; //< is readibleshortis_w; //< is writable shortis_x; //< is executableshortis_p; //< is privatelongoffset; //< offsetchardev[12]; //< the device that backs the region, format major:minorintinode; //< inode of the file that backs the areacharpathname[600];//< the path of the file that backs the area//The next region in the liststructprocmaps_struct*next; //<handler of the chinaed list
}After cloning, building this project is possible as follows:
$ cd [proc_maps_parser checkout]
$ make # to build it as a static library
$ make examples # to build both the static library and the example program
Optionally, the BUILD_DIR environment variable can be specified when running make to build the static library somewhere else. By default, this is set to a build/ directory in the root of the source tree.
from ./examples/map.c
intpid=-1; //-1 to use the running process id, use pid>0 to list the map of another processprocmaps_iterator*maps=pmparser_parse(pid);
if(maps==NULL){
printf ("[map]: cannot parse the memory map of %d\n",pid);
return-1;
}
//iterate over areasprocmaps_struct*maps_tmp=NULL;
while( (maps_tmp=pmparser_next(maps)) !=NULL){
pmparser_print(maps_tmp,0);
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~\n"); }
//mandatory: should free the listpmparser_free(maps);