Resident Set Size (RSS) from /proc/pid/stat

Most UNIX-like systems have information about processes stored in /proc/$pid/ files, so does Linux.

If you would want to get the Resident Set Size (RSS) of a process on Linux you could find this in a number of files:

/proc/$pid/stat
targetted for scanf(3)
/proc/$pid/statm
targetted for scanf(3) but just memory information (more detailed)
/proc/$pid/status
targetted at humans

Oddly enough if you check these three files for the RSS memory you will get different results! It seem both stat and statm have the wrong RSS information. It is a mystery to me why.