Check for a pid in bash with out pgrep
pid_check() {
local PID=$1
local i
for i in `ps ax | awk 'BEGIN { FS = "[ \t]+" } ; { print $1 ;print $2 }'| grep $PID`; do
if [ "$PID" -eq "${i:=''}" ] ; then
echo "Matched $PID"
return 0;
fi
echo "$i"
done
return 1;
}
pid_check 1068
local PID=$1
local i
for i in `ps ax | awk 'BEGIN { FS = "[ \t]+" } ; { print $1 ;print $2 }'| grep $PID`; do
if [ "$PID" -eq "${i:=''}" ] ; then
echo "Matched $PID"
return 0;
fi
echo "$i"
done
return 1;
}
pid_check 1068
Comments