標籤:睡眠 進程狀態 c盤 lap lines 視窗 rip logs adb shell
一個個在手機 設定\程式管理 一個個 結束進程好麻煩,也不想因為這個再去安裝 app管理軟體,不如寫個指令碼 一鍵清理
此 指令碼要 手機Root(主要是把檔案放入\system\bin 下,並設定為可執行,不root無法使用chomd命令)
Adb 調試工具,網上一大堆,可自行下載
說思路
- 擷取進程的包名(因為包名比PPID 更能讓人看的懂)
- 產生個含有要結束進程的檔案
- 把所有要結束的進程寫入指令碼,放入手機並設定可運行
- 手機直接執行指令碼
好,動手環節
先用 命令adb shell ps >c:\app.txt 擷取進程及包名,並寫入 C盤的 app.txt 文本內.
各欄位的含義:
USER 進程目前使用者
PID 進程ID
PPID 父進程ID
VSIZE 進程的虛擬記憶體大小,以KB為單位
RSS 實際佔用的記憶體大小,以KB為單位
WCHAN 進程正在睡眠的核心功能名稱;
PC Program Counter
NAME 進程狀態及名稱
可以用命令 adb shell am force-stop 包名 來結束進程 ,如 酷我音樂盒 。就是
adb shell am force-stop cn.kuwo.player
從 app.txt 分離出包名,這裡我用的 是python 的指令碼,擷取com.xxx.xxx與cn.xxx.xxx 開頭的包名(國內多數的安卓程式多用這兩個)
Python 的代碼如下 arry.py
1 #coding=utf-8 2 import os 3 import math 4 5 prefix ="echo -e am force-stop " 6 perfixEndFirst =" >/system/bin/d" 7 perfixEnd =" >>/system/bin/d" 8 resultArr =[] 9 resultStr=""10 11 f=open(‘app.txt‘, ‘r‘)12 s=f.readlines()13 #count = len(s)14 15 for t in range(1,len(s)):16 str = s[t-0]17 if str != None and "000 S " in str:18 strSName = str.split("000 S ") 19 if strSName[1] != None:20 strName = strSName[1].replace(" S ","")21 if strName.startswith("com.") or strName.startswith("cn."):22 #插入數組23 resultArr.insert(0,strName.strip(‘\n‘))24 print(strName)25 26 27 #resultStr = resultStr + "echo " + "#!/system/bin/sh" + perfixEndFirst +"\n" 28 for r in resultArr:29 resultStr = resultStr + prefix + r+ perfixEnd+"\n" 30 31 resultStr = resultStr + ‘echo -e "echo Success!" >>/system/bin/d‘ 32 with open("d.sh","w") as f:33 f.write(resultStr)34 35 os.system(‘pause‘)
View Code
在其目錄下 產生一個 叫”d.sh”的檔案,(d就是delete的首字母)
我們可以用記事本開啟 在d.sh 檔案,其結果如 下
這裡,我是用 echo 將字串寫入手機的 /system/bin/d 檔案內,而不是 將檔案push到 手機上,不知道為什麼產生了亂碼與不能換行(不方便閱讀與維護)
可以將 s.sh 全部複製到黏貼板,開啟一個adb 的調試視窗並提權到root,然後黏貼
然後 設定檔案d 為可執行 chmod 777 /system/bin/d
然後,就可以在 普通使用者下,調用該指令碼了,
運行結束會的 Success! 提示
在手機上用 “終端模擬器”,調用時要su 一下,不提權會出錯,個人現在還沒有弄明白為什麼
清除後台,一身輕鬆。。
如果後期加入別的 包名中微博,可以在 寫入
echo -e am force-stop com.sina.weibo >>/system/bin/d 即可。
安卓手機進程清理