here's the paradigm I usually use on Solaris of detecting another instance of the same running script. If another instance IS detected, the current (the calling instance) will exit allowing the 'older' instance to finish its work.
It's not exactly what you want, but might be a good starting point:
Code:
#!/bin/ksh
thisFILE="$(whence ${0})"
progNameFull="${0##*/}"
progName="${progNameFull%%.*}"
AWK='/bin/nawk'
FUSER='/usr/sbin/fuser'
#----------------------------------------------------------------------
# see if there's another instance of THIS script running - don't allow MULTIPLE
# instances of the same script running at the same time. If there's a previously
# invoked instance of this script running, log an error message and exit THIS
# current invocation of the script - allow the previously invoked script finish
# its own workload.
myPID="$$"
FUSERout=$(${FUSER} ${thisFILE} 2>/dev/null)
# echo "fuser ->[${FUSERout}]"
typeset -i numProc=$(echo "${FUSERout}" | ${AWK} '{print NF}')
if [[ "${numProc}" -gt 1 ]] ; then
echo "${progName}::main Error: another instance(s) of [${thisFILE}] is currently still running [$(echo ${FUSERout} | sed -e 's/ */ /g')] - exiting THIS [${myPID}] run."
exit 1
fi