Skip to content

Instantly share code, notes, and snippets.

@cgould
Last active August 29, 2015 14:27
Show Gist options
  • Save cgould/fa7e4e821c68997f3f34 to your computer and use it in GitHub Desktop.
Save cgould/fa7e4e821c68997f3f34 to your computer and use it in GitHub Desktop.
List android running packages with their start time
#/bin/bash
uptime=$(adb shell cat /proc/uptime | awk '{print int($1)}' )
apps=$(adb shell pm list packages | sed s/package:// | sed $'s/\x0D//' | awk '{printf "%s\\\|", $0} END {printf "@@@\n"}')
adb shell ps | grep `echo $apps` | while read line ;
do
pid=$(echo -n $line | awk '{print int($2)}')
name=$(echo -n $line| awk '{printf "%s", $NF}'| sed $'s/\x0D//')
starttime=$(adb shell cat /proc/$pid/stat | awk '{print int($22 / 100)} ')
now=$(date +%s)
diff=$((now-(uptime-starttime)))
diffp=$(date -r $diff)
printf "%s - %s\n" "$diffp" "$name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment