Wednesday, February 25, 2009

Change Your Data To Suit Your Program

You may have some proven utilities developed in Solaris 8 that are based on pmap output and would love to port them to Solaris 10. Or you may just want to maintain a single version to handle both Solaris 8 and Solaris 10. However, the output from pmap is different from the two Solaris versions. So, shall we modify the scripts ?

Do you know that you can have another alternative. Yes, it is to change the output to suit your existing program. In this case, you do not have to go through all the testings to ensure the correctness of your scripts.

What you can do is to run a customised function (_pmap) to convert the pmap output for Solaris 10, else run the original pmap command for Solaris 8.

Here are the sample outputs and the pmap function (_pmap). The rest of your script can remain intact.

solaris8$ pmap $$
29778:  sh -i
00010000    200K read/exec         /usr/bin/ksh
00052000      8K read/write/exec   /usr/bin/ksh
00054000     40K read/write/exec     [ heap ]
FF180000    688K read/exec         /usr/lib/
FF23C000     32K read/write/exec   /usr/lib/
FF280000    576K read/exec         /usr/lib/
FF310000     40K read/write/exec   /usr/lib/
FF31A000     24K read/write/exec   /usr/lib/
FF340000     16K read/exec         /usr/lib/
FF354000      8K read/write/exec   /usr/lib/
FF360000      8K read/write/exec   /usr/lib/
FF370000      8K read/write/exec     [ anon ]
FF380000     40K read/exec         /usr/lib/
FF39A000      8K read/write/exec   /usr/lib/
FF3A0000      8K read/exec         /usr/platform/sun4u-us3/lib/
FF3B0000    192K read/exec         /usr/lib/
FF3E0000      8K read/write/exec   /usr/lib/
FF3E2000      8K read/write/exec   /usr/lib/
FFBEC000     16K read/write          [ stack ]
 total     1928K

solaris10$ pmap $$
1742:   bash
00010000     648K r-x--  /usr/bin/bash
000C0000      80K rwx--  /usr/bin/bash
000D4000     184K rwx--    [ heap ]
FF100000     864K r-x--  /lib/
FF1E8000      32K rwx--  /lib/
FF1F0000       8K rwx--  /lib/
FF200000     584K r-x--  /lib/
FF2A2000      40K rwx--  /lib/
FF2AC000      24K rwx--  /lib/
FF2BE000       8K rwxs-    [ anon ]
FF2D0000       8K r-x--  /platform/sun4u-us3/lib/
FF2E0000       8K r-x--  /lib/
FF2F2000       8K rwx--  /lib/
FF300000       8K rwx--    [ anon ]
FF310000      48K r-x--  /lib/
FF32C000       8K rwx--  /lib/
FF340000     168K r-x--  /lib/
FF37A000      32K rwx--  /lib/
FF382000       8K rwx--  /lib/
FF390000      24K rwx--    [ anon ]
FF3A0000       8K r--s-  dev:85,0 ino:42159
FF3B0000     208K r-x--  /lib/
FF3F4000       8K rwx--  /lib/
FF3F6000       8K rwx--  /lib/
FFBFC000      16K rw---    [ stack ]
 total      3040K

        /usr/bin/pmap $1 | awk '
        NF>=4 {
                printf("%-10s %8s ", $1, $2)
                if ( substr($3,1,1) == "r" ) { mode=sprintf("read") }
                if ( substr($3,2,1) == "w" ) { mode=sprintf("%s/write", mode) }
                if ( substr($3,3,1) == "x" ) { mode=sprintf("%s/exec", mode) }
                if ( substr($3,4,1) == "s" ) { mode=sprintf("%s/shared", mode) }

                printf("%-18s ",mode)
                for(i=4;i<=NF;++i) {
                        printf("%s ",$i)

case `uname -r` in
        echo "Unknown solaris version"
        exit 1

$PMAP ....

Labels: ,


Post a Comment

<< Home