-
Notifications
You must be signed in to change notification settings - Fork 4
/
a-kill
executable file
·70 lines (66 loc) · 2.01 KB
/
a-kill
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Copyright (C) 2012 Texas Instruments
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: Gabriel M. Beddingfield <[email protected]>
#
# DESCRIPTION OF a-kill
# ---------------------
#
# Kills all processes on target device that match a string.
#
# For example:
#
# $ a-kill mediaserver
#
# Will kill all processes that have 'mediaserver' in the command line.
# There is usually only one called 'mediaserver'. However:
#
# $ a-kill media
#
# Will kill all process that have 'media' in the command line. There
# are usually three.
#
# If you want to try first, then you can use the -d option for
# "dry run." It will show you the processes that it would have killed.
#
# The program depends on 'adb' being in the current path, and ps being
# the default one supplied by android. (E.g. this won't work with
# the ps supplied by busybox.)
#
if [ $# -lt 1 ] ; then
echo "Usage: a-kill <case-insensitive-string> [-d]"
echo " -d for a dry-run (don't actually kill anything)"
echo
echo "Example: a-kill mediaserver"
exit
fi
DRY_RUN=no
if [ "$2" == "-d" ] ; then
DRY_RUN=yes
fi
while [ $# -ge 1 ] ; do
for LINE in $(adb shell ps | awk '{print $2 ";" $9}' | grep -i "$1") ; do
LINE=$(echo "$LINE" | sed 's/\x0D//') # Remove DOS line endings
APID=$(echo "$LINE" | sed 's/;.*//')
NAME=$(echo "$LINE" | sed 's/^[0-9]\{1,\};//')
if [ "$DRY_RUN" = "yes" ] ; then
echo "Would kill $NAME (pid=$APID)"
else
echo "Killing $NAME (pid=$APID)"
adb shell kill "$APID"
fi
done
shift
done