#!/usr/local/bin/bash
# My "getparent pid" logic in bash:
# Get the PID of the given command. If there's more than one instance running
# then returns a list of all PIDs.
#
# This is equivalent to pidof:
# ps h -Cp4d -opid
getpid ()
{
pidof $1
}
# If there are multiple instances of the given command then return their
# parent pid, otherwise returns nothing
getparent ()
{
ps -ef |awk 'BEGIN{parent=0}/'$1' /{if (parent != $3) {parent = $3} else {print $3; exit}}'
}
# Get the pid of the master p4d instance
p4getpid ()
{
count=`getpid p4d |wc -w`
if [ $count -eq 1 ]; then
getpid p4d
else
getparent p4d
fi
}