Listing 10 get_resource_holder
{
# Echos the process id (pid) of the process that currently has a
# particular resource.
local FUNC_NAME=get_resource_holder
${TRACE:-trace $FUNC_NAME $@}
local semaphore=$1
integer resource_num=$2
local pid
local resource=$HOME_DIR/$semaphore/$RESOURCES_DIRNAME/$resource_num
assert_semaphore $semaphore
if [[ -L $resource ]]
then
pid=$(get_link_target $resource)
if [[ -n $pid ]]
then
if is_non_negative_integer $pid
then
echo $pid
return 0
fi
fi
elif [[ -f $resource ]]
then
rm -f $resource # regular files shouldn't exist
fi
return 1
} |