David> Hello, I'm trying to retrieve the memory usage of
David> current process, as the ps command does. I did not find the
David> source code for this command, then I ask here if anybody
David> could help in this issue. I found the getrusage system
David> call, but the linux implementation (and most of
David> implementation) is not complete, making this call quite
David> useless. Any idea ?
Use the /proc filesystem. If you want to retrieve detailed memory
usage on your own process, you can read the following files (textual
files)
/proc/self/status - which has a VmSize: line
/proc/self/stat
/proc/self/statm
and the whole memory map is
/proc/self/maps
If you want to know about another process, for example the process of
pid 1234, use /proc/1234/status /proc/1234/maps etc...
The detailed format of the output of /proc files is documented in the
kernel sources, in particular in
/usr/src/linux/Documentation/filesystems/proc.txt
[If David is frenchspeaking he could email me in French if he wishes]
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net
aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
8, rue de la Fa?encerie, 92340 Bourg La Reine, France