#!/bin/sh
###############################################################
# detectpid: Pid detection script
# Ver.2.0.1
# Written by T.Nonogaki(http://www.asahi-net.or.jp/^aa4t-nngk/)
###############################################################
PSCOMM="ps axwwo pid,args"
ME=$(echo $0 |sed 's/\//\\\//g')

REGEX=
for i; do
	REGEX="$REGEX && /${i}/"
done

$PSCOMM |awk "
	(\$1 == $$) || (\$1 == PROCINFO[\"pid\"]) { next; }
	!/$ME/ && !/$PSCOMM/ $REGEX { print \$1; exit 0; }
"
