I want to extract the information from
/proc/pid/maps, such as: the start address, the end address, and the permission.
However, for learning purpose, I want to use the low-level system call, such as:
I am confused how to grep the information I need. There are some challenges I found:
- How to read the whole file using
Right now, I am using
while((n = read(fd, buf, BUFSIZ)) > 0), to read the file, but apparently it reads in multiple batch, increasing the
BUFSIZ * 2, does not solve the problem.
- I am trying to grep the start address, by, read the character one by one until I find the
-separator, and then
lseekto the first character in the line and use
readto get the start address. It works fine for the first iteration, but it mess up for the second iteration of
while((n = read(fd, buf, BUFSIZ)) > 0).
What is the best way to extract the information?