Logowww.asingh.netHomeNewsBioInterestsTechnicalSearchContact



 Archive :

  May 2006
  June 2006
  July 2006
  July 2007
  August 2007
  April 2008
  June 2008
  December 2008
  January 2009
  March 2009
  June 2009
  January 2010

What's Going On In My System's Memory ?

Ever wonder what's going on in your system's memory (RAM) ? Solaris provides a mdb dcmd ::memstat , which provides the status of all the pages in memory. Following is an example of "memstat" in action on my Solaris 10 machine.

jalandhar% su
Password:
# memstat
# mdb -k
Loading modules: [ unix krtld genunix specfs dtrace ufs sd ip sctp usba fctl nca nfs audiosup random sppp ptm ipc ]
> ::memstat
Page Summary Pages MB %Tot
------------ ---------------- ---------------- ----
Kernel 13643 106 5%
Anon 43533 340 17%
Exec and libs 8669 67 3%
Page cache 5757 44 2%
Free (cachelist) 23950 187 9%
Free (freelist) 163652 1278 63%

Total 259204 2025
Physical 255368 1995




Similarly, there is another tool, pmap, that can be used to look at the address space mapping of a process. "pmap" is one of the /proc file-system based utility and provides output as follows. See "man pmap" for more detail.

jalandhar% pmap 791
791: /bin/ksh -p /usr/sfw/bin/mozilla
00010000 200K r-x-- /usr/bin/ksh
00052000 8K rwx-- /usr/bin/ksh
00054000 48K rwx-- [ heap ]
FF280000 848K r-x-- /lib/libc.so.1
FF364000 32K rwx-- /lib/libc.so.1
FF36C000 8K rwx-- /lib/libc.so.1
FF38E000 8K rwxs- [ anon ]
FF398000 16K r-x-- /platform/sun4u/lib/libc_psr.so.1
FF3A0000 24K rwx-- [ anon ]
FF3B0000 176K r-x-- /lib/ld.so.1
FF3EC000 8K rwx-- /lib/ld.so.1
FF3EE000 8K rwx-- /lib/ld.so.1
FFBFC000 16K rw--- [ stack ]
total 1400K

posted by Amandeep 5/29/2006 02:12:00 PM | PERMALINK

C Macro For Printing Filename And Line Number

Most C compilers provide the macros __FILE__ and __LINE__ that can be used to print the source file name and line number respectively. These macros come in handy when printing debug information or when using printf() as a general purpose tool for debugging. Imagine a program that allocates memory via malloc(). As a good programming practice, before using the pointer returned by malloc() it has to be ensured that the allocation succeeded (i.e. the pointer returned by malloc() is not NULL). If the memory allocation fails, the program will probably have to give a message indicating this. Now, there can be several malloc() calls through out the program - which one failed? Well use of __FILE__ and __LINE__ macros make it easy to find.

Similarly, a statement like: "printf("%s:%d\n", __FILE__, __LINE__); " , if used appropriately can be used to follow the flow of a program. Ofcourse, this is a crude way of doing something that can be easily done through any standard debugger, without having to change code. Nonetheless, it can come in handy depending on the situation.

posted by Amandeep 5/15/2006 11:19:00 PM | PERMALINK

 

 

| Home | News | Bio | Interests | Technical | Search | Contact |

This page is powered

by Blogger.