#! /bin/sh
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#

# Kills any process which has the Shared memory opened
# It loops for each directory (pid) in the /proc directory
# executes pmap on each pid. If the pid contains the shared
# memory then it deletes it.

# $2,$3,$4 is the shared memory ID in hex values
# $1 is the pid of the kixhashut executable, which should not be deleted 

search_1()
{
pmap $i | grep $search1 2>/dev/null >/dev/null
if [ $? -eq 0 ]
   then
       echo 'KIX7561I: Killing process ' $i 
       kill -9 $i
       Killed=1 
fi
return 0
}

search_2()
{
pmap $i | grep $search2 2>/dev/null >/dev/null
if [ $? -eq 0 ]
   then
       echo 'KIX7561I: Killing process ' $i 
       kill -9 $i
       Killed=1 
fi
return 0
}

search_3()
{
pmap $i | grep $search3 2>/dev/null >/dev/null
if [ $? -eq 0 ]
   then
       echo 'KIX7561I: Killing process ' $i 
       kill -9 $i
       Killed=1 
fi
return 0
}

# 
# Main program
#

search1="shmid=0x"$2
search2="shmid=0x"$3
search3="shmid=0x"$4

cd /proc

for i in *
do
   if [ $i -eq $1 ]
      then
      a=$a
   else 
        Killed=0
        pmap $i 2>/dev/null >/dev/null
        Permission=$?
        if [ $Permission -eq 0 ] 
           then
           search_1
        fi
        if [ $Killed -eq 0 ] && [ $Permission -eq 0 ]
              then
              search_2
        fi
        if [ $Killed -eq 0 ] && [ $Permission -eq 0 ]
              then
              search_3
        fi
   fi
done
