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/libc.so.1
FF23C000     32K read/write/exec   /usr/lib/libc.so.1
FF280000    576K read/exec         /usr/lib/libnsl.so.1
FF310000     40K read/write/exec   /usr/lib/libnsl.so.1
FF31A000     24K read/write/exec   /usr/lib/libnsl.so.1
FF340000     16K read/exec         /usr/lib/libmp.so.2
FF354000      8K read/write/exec   /usr/lib/libmp.so.2
FF360000      8K read/write/exec   /usr/lib/libdl.so.1
FF370000      8K read/write/exec     [ anon ]
FF380000     40K read/exec         /usr/lib/libsocket.so.1
FF39A000      8K read/write/exec   /usr/lib/libsocket.so.1
FF3A0000      8K read/exec         /usr/platform/sun4u-us3/lib/libc_psr.so.1
FF3B0000    192K read/exec         /usr/lib/ld.so.1
FF3E0000      8K read/write/exec   /usr/lib/ld.so.1
FF3E2000      8K read/write/exec   /usr/lib/ld.so.1
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/libc.so.1
FF1E8000      32K rwx--  /lib/libc.so.1
FF1F0000       8K rwx--  /lib/libc.so.1
FF200000     584K r-x--  /lib/libnsl.so.1
FF2A2000      40K rwx--  /lib/libnsl.so.1
FF2AC000      24K rwx--  /lib/libnsl.so.1
FF2BE000       8K rwxs-    [ anon ]
FF2D0000       8K r-x--  /platform/sun4u-us3/lib/libc_psr.so.1
FF2E0000       8K r-x--  /lib/libdl.so.1
FF2F2000       8K rwx--  /lib/libdl.so.1
FF300000       8K rwx--    [ anon ]
FF310000      48K r-x--  /lib/libsocket.so.1
FF32C000       8K rwx--  /lib/libsocket.so.1
FF340000     168K r-x--  /lib/libcurses.so.1
FF37A000      32K rwx--  /lib/libcurses.so.1
FF382000       8K rwx--  /lib/libcurses.so.1
FF390000      24K rwx--    [ anon ]
FF3A0000       8K r--s-  dev:85,0 ino:42159
FF3B0000     208K r-x--  /lib/ld.so.1
FF3F4000       8K rwx--  /lib/ld.so.1
FF3F6000       8K rwx--  /lib/ld.so.1
FFBFC000      16K rw---    [ stack ]
 total      3040K



_pmap()
{
        /usr/bin/pmap $1 | awk '
        NF>=4 {
                printf("%-10s %8s ", $1, $2)
                mode=""
                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)
                }
                printf("\n")
                next
        }
        {
                print
        }'
}

case `uname -r` in
5.8)
        PMAP="/usr/proc/bin/pmap"
        ;;
5.10)
        PMAP=_pmap
        ;;
*)
        echo "Unknown solaris version"
        exit 1
        ;;
esac


$PMAP ....

Labels: ,

0 Comments:

Post a Comment

<< Home