Merge "Add --exact flag to pid tool; new qpid tool."

This commit is contained in:
Daniel Sandler 2013-08-02 01:49:32 +00:00 committed by Android (Google) Code Review
commit c86b05f807

View file

@ -774,15 +774,50 @@ function cproj()
echo "can't find Android.mk"
}
# simplified version of ps; output in the form
# <pid> <procname>
function qpid() {
local prepend=''
local append=''
if [ "$1" = "--exact" ]; then
prepend=' '
append='$'
shift
elif [ "$1" = "--help" -o "$1" = "-h" ]; then
echo "usage: qpid [[--exact] <process name|pid>"
return 255
fi
local EXE="$1"
if [ "$EXE" ] ; then
qpid | grep "$prepend$EXE$append"
else
adb shell ps \
| tr -d '\r' \
| sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
fi
}
function pid()
{
local EXE="$1"
if [ "$EXE" ] ; then
local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
echo "$PID"
else
echo "usage: pid name"
fi
local prepend=''
local append=''
if [ "$1" = "--exact" ]; then
prepend=' '
append='$'
shift
fi
local EXE="$1"
if [ "$EXE" ] ; then
local 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>"
return 255
fi
}
# systemstack - dump the current stack trace of all threads in the system process