diff --git a/envsetup.sh b/envsetup.sh index 6ed3863b3..c2f13b34e 100644 --- a/envsetup.sh +++ b/envsetup.sh @@ -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