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: open
, read
, and lseek
.
I am confused how to grep the information I need. There are some challenges I found:
- How to read the whole file using
read()
?
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 thenlseek
to the first character in the line and useread
to get the start address. It works fine for the first iteration, but it mess up for the second iteration ofwhile((n = read(fd, buf, BUFSIZ)) > 0)
.
What is the best way to extract the information?