Add return code support to pid. am: 4df6279c71

am: 3502ceecff

Change-Id: Ia797e9e3b9732e258d24528ad42f6b78edf6c87d
This commit is contained in:
Josh Gao
2018-06-15 08:58:51 -07:00
committed by android-build-merger

View File

@@ -14,22 +14,29 @@
# limitations under the License.
# Get the pid of processes matching a string.
prepend=''
append=''
EXACT=0
if [ "$1" = "--exact" ]; then
prepend=' '
append='$'
EXACT=1
shift
fi
EXE="$1"
if [ "$EXE" ] ; then
PID=`adb shell ps \
| tr -d '\r' \
| \grep "$prepend$EXE$append" \
| sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
echo "$PID"
else
if ! [ "$EXE" ] ; then
echo "usage: pid [--exact] <process name>"
exit 255
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