forked from openkylin/platform_build
Add --exact flag to `pid` tool; new `qpid` tool.
The new --exact flag for pid does an exact match on the process name, rather than grepping anywhere in the ps output, which helps target a specific process if its name is a substring of another process name. (Nothing else about pid's output, including inclusion of the ps header if it matches, is affected.) qpid ("quick pid" or "quiet pid") lists all processes in the following simplified format: <pid> <procname> It also helpfully strips off the header line from ps. With an argument, qpid will search for processes or pids matching the argument. With --exact it matches process names exactly (as does pid, above). Change-Id: I28a201df40281a66cb1a2918b7ee3a0b2d7b6ffd
This commit is contained in:
parent
2b3bd4a88b
commit
47e0a88dbc
43
envsetup.sh
43
envsetup.sh
|
@ -774,14 +774,49 @@ function cproj()
|
|||
echo "can't find Android.mk"
|
||||
}
|
||||
|
||||
function pid()
|
||||
{
|
||||
# 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
|
||||
local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
|
||||
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 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 name"
|
||||
echo "usage: pid [--exact] <process name>"
|
||||
return 255
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue