--- pmap.c +++ pmap.c 2007-06-11 17:22:37.794874038 +0200 @@ -16,6 +16,7 @@ #include #include #include +#include #include "proc/readproc.h" #include "proc/version.h" @@ -30,6 +31,7 @@ struct smap { unsigned long shared_dirty; unsigned long private_clean; unsigned long private_dirty; + unsigned long referenced; }; static unsigned long mapped; @@ -37,7 +39,9 @@ static unsigned long shared; static unsigned long private; static unsigned long rss; static unsigned long dirty; +static unsigned long referenced; static FILE *smaps_fp; +static int maj, min, patch; static void usage(const char *cmd) { @@ -123,6 +127,19 @@ static int get_smap_data(struct smap *sm smap->private_dirty = data; dirty += data; + if ((maj < 2) || ((maj == 2) && ((min < 6) || ((min == 6) && (patch < 22))))) + return 0; + + /* get referenced */ + if (!fgets(buff, BUFFERSIZE, smaps_fp)) + return 1; + + assigned = sscanf(buff, "Referenced: %lld", &data); + if (assigned != 1) + return 1; + smap->referenced = data; + referenced += data; + return 0; } @@ -181,8 +198,12 @@ int main(int argc, char *argv[]) char path[PATH_MAX]; char buff[BUFFERSIZE]; int o, show_devices = 0, quiet = 0; + struct utsname uts; pid_t pid; + if (uname(&uts) == 0) + sscanf(uts.release, "%d.%d.%d", &maj, &min, &patch); + struct option longopts[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, @@ -264,8 +285,12 @@ int main(int argc, char *argv[]) else printf("mapped: %luK ", mapped); - printf("%luK writable-private, %luK readonly-private, and %luK shared\n", - private, mapped - private - shared, shared); + if ((maj < 2) || ((maj == 2) && ((min < 6) || ((min == 6) && (patch < 22))))) + printf("%luK writable-private, %luK readonly-private, and %luK shared\n", + private, mapped - private - shared, shared, referenced); + else + printf("%luK writable-private, %luK readonly-private, %luK shared, and %luK referenced\n", + private, mapped - private - shared, shared, referenced); } return 0;