2011-04-26

Get gcc Hidden Macro Definition

> touch /tmp/x.c
> gcc -E -dM -c /tmp/x.c

#define __linux__ 1
#define linux 1
#define __i386__ 1
#define __i386 1
#define __GNUC_MINOR__ 95
#define i386 1
#define __unix 1
#define __unix__ 1
#define __GNUC__ 2
#define __linux 1
#define __ELF__ 1
#define unix 1

Read Memory Usage

How to read memory usage of a process from /proc/pid/status

VmPeak:     8368 kB  (peak usage of virtual memory)
VmSize:     7344 kB  (usage of virtual memory)
VmLck:         0 kB  (locked memory)
VmHWM:      2336 kB  (peak usage of hardware memory)
VmRSS:      2336 kB  (usage of hardware memory)
VmData:     3052 kB  (heap)
VmStk:        88 kB  (stack)
VmExe:        16 kB  (text section)
VmLib:      4080 kB  (shared library)
VmPTE:        56 kB  (page table entry size)

Explanation comes from:
http://d.hatena.ne.jp/naoya/20080727/1217119867
http://www.kernel.org/doc/man-pages/online/pages/man5/proc.5.html
http://www.linuxquestions.org/questions/programming-9/vmsize-regarding-proc-pid-status-432227/