if [ -n "$PID" -a -e /proc/$PID ]; then
echo "process exists"
fi
or
if [ -n "$(ps -p $PID -o pid=)" ]
In the latter form, -o pid=
is an output format to display only the process ID column with no header. The quotes are necessary for non-empty string operator -n
to give valid result.