Add return code support to pid.
Test: pid nonexistent; echo $? Test: pid --exact nonexistent; echo $? Change-Id: If8efb1ca27ae3ed7b5be1c51179fae387c56e305
This commit is contained in:
29
scripts/pid
29
scripts/pid
@@ -14,22 +14,29 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# Get the pid of processes matching a string.
|
# Get the pid of processes matching a string.
|
||||||
prepend=''
|
EXACT=0
|
||||||
append=''
|
|
||||||
if [ "$1" = "--exact" ]; then
|
if [ "$1" = "--exact" ]; then
|
||||||
prepend=' '
|
EXACT=1
|
||||||
append='$'
|
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
EXE="$1"
|
EXE="$1"
|
||||||
if [ "$EXE" ] ; then
|
if ! [ "$EXE" ] ; then
|
||||||
PID=`adb shell ps \
|
|
||||||
| tr -d '\r' \
|
|
||||||
| \grep "$prepend$EXE$append" \
|
|
||||||
| sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
|
|
||||||
echo "$PID"
|
|
||||||
else
|
|
||||||
echo "usage: pid [--exact] <process name>"
|
echo "usage: pid [--exact] <process name>"
|
||||||
exit 255
|
exit 255
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $EXACT == 1 ]; then
|
||||||
|
PIDS="$(adb shell pidof $EXE)"
|
||||||
|
RC=$?
|
||||||
|
else
|
||||||
|
PIDS=$(adb shell "ps -o PID,NAME | tail -n +1 | grep $EXE | tr -s ' ' | cut -f2 -d' '")
|
||||||
|
[ -n "$PIDS" ]
|
||||||
|
RC=$?
|
||||||
|
fi
|
||||||
|
|
||||||
|
for PID in $PIDS; do
|
||||||
|
echo $PID
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $RC
|
||||||
|
|||||||
Reference in New Issue
Block a user