Under Linux (and Unix like) operating systems each user mode process get its own separate range of liner address. Further, each process' liner address are divided into virtual memory (also known as regions) areas. Linux kernel can assign differnet access rights to each regions such as:
- Read only region
- Write only region
- Exec only region
- Share only region
This is useful for performance as well as saving memory space (RAM). For example, on a Linux shell server at local university 100s of user can run pine e-mail client to read their emails. It would be very difficult to have to keep a separate copy of the email client in memory for each user / process. So, with the help of virtual memory, Linux kernel can map the memory regions that contains the executable code into the address space for each process.
Each process has the following areas:
- Code
- Data
- Heap
- Stack
- Arguments and Environments
Command to see process address space
First, find out the pid of given process such as firefox:
$ ps aux | grep [f]irefox
Sample outputs (node PID 3901):
vivek 3901 4.5 4.2 1226760 343880 ? Sl Oct31 27:17 /opt/firefox/firefoxTo view Firefox process address space, enter:
$ cat /proc/3901/status
Sample outputs:
Name: firefox State: S (sleeping) Tgid: 3901 Pid: 3901 PPid: 1 TracerPid: 0 Uid: 1000 1000 1000 1000 Gid: 1000 1000 1000 1000 FDSize: 128 Groups: 7 24 25 29 30 44 46 109 110 111 116 1000 VmPeak: 1261072 kB VmSize: 1224456 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 574280 kB VmRSS: 333700 kB VmData: 737892 kB VmStk: 252 kB VmExe: 88 kB VmLib: 55932 kB VmPTE: 2152 kB VmSwap: 0 kB Threads: 27 SigQ: 0/16382 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000001000 SigCgt: 00000001800144ef CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: ffffffffffffffff Cpus_allowed: ff Cpus_allowed_list: 0-7 Mems_allowed: 00000000,00000001 Mems_allowed_list: 0 voluntary_ctxt_switches: 5136549 nonvoluntary_ctxt_switches: 194593
You can also use a pmap command to get a detailed memory map of a process:
$ pmap PID
$ pmap 3901 | less
$ pmap -x 3901 | less
Sample outputs:
3901: /opt/firefox/firefox Address Kbytes RSS Dirty Mode Mapping 0000000000400000 0 76 0 r-x-- firefox 0000000000615000 0 4 4 rw--- firefox 00007f77c918c000 0 0 0 ----- [ anon ] 00007f77c918d000 0 12 12 rw--- [ anon ] 00007f77c998d000 0 168 0 r---- icon-theme.cache 00007f77cccfc000 0 0 0 ----- [ anon ] 00007f77cccfd000 0 12 12 rw--- [ anon ] 00007f77ce200000 0 1024 1024 rw--- [ anon ] 00007f77ce3b6000 0 168 0 r---- icon-theme.cache 00007f77cefff000 0 0 0 ----- [ anon ] 00007f77cf000000 0 1044 1044 rw--- [ anon ] 00007f77cfa00000 0 176 176 rw--- [ anon ] 00007f77cfb00000 0 5176 5176 rw--- [ anon ] 00007f77d0300000 0 840 840 rw--- [ anon ] 00007f77d0500000 0 1208 1208 rw--- [ anon ] 00007f77d07fe000 0 8 0 r-x-- pango-indic-lang.so 00007f77d0800000 0 0 0 ----- pango-indic-lang.so 00007f77d09ff000 0 4 4 rw--- pango-indic-lang.so .... .. .. 00007f781a92a000 0 76 0 r--s- e13b20fdb08344e0e664864cc2ede53d-le64.cache-3 00007f781a93d000 0 36 36 rw--- [ anon ] 00007f781aa42000 0 8 0 r---- spdyindicator@chengsun.github.com.xpi 00007f781aa45000 0 4 0 r--s- mime.cache 00007f781aa46000 0 4 4 rw--- [ anon ] 00007f781aa47000 0 80 0 r--s- 865f88548240fee46819705c6468c165-le64.cache-3 00007f781aa5b000 0 12 0 r--s- bbea2db9e2218396b4c79114bcec762f-le64.cache-3 00007f781aa5e000 0 28 0 r--s- gconv-modules.cache 00007f781aa65000 0 8 8 rw--- [ anon ] 00007f781aa67000 0 4 4 r---- ld-2.11.3.so 00007f781aa68000 0 4 4 rw--- ld-2.11.3.so 00007f781aa69000 0 4 4 rw--- [ anon ] 00007fff3f8a3000 0 208 208 rw--- [ stack ] 00007fff3f9af000 0 4 0 r-x-- [ anon ] ffffffffff600000 0 0 0 r-x-- [ anon ] ---------------- ------ ------ ------ total kB 1222600 334852 297184
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 3 comments… read them below or add one }
this is a good command
thanks its good info to check any process internals :)
Also check this SO question:
http://stackoverflow.com/questions/131303/linux-how-to-measure-actual-memory-usage-of-an-application-or-process/