当前位置:网站首页>如何徹底强制殺死後臺無關進程?
如何徹底强制殺死後臺無關進程?
2022-07-23 21:47:00 【飛猿_SIR】
在一些低端機型或小內存的ROM中,經常會出現內存不足的情况,除了優化自身程序外,往往需要通過殺死清空一些無關的後臺進程來節省內存。但現在許多程序都做了很强的守護進程或加入了平臺白名單,常規方法都無法徹底殺死。
比如am.forceStopPackage(),或者 "adb shell killall -9 com.xxx.xxx".都是殺掉後一會又會自啟。那麼對於這種情况,改如何徹底幹掉這些討厭的家夥呢。
這裏提供一種非常規方法,通過禁用該包名來實現,不過需要注意的是,禁用包名後,對應程序進程會被清空,而且無法再啟動,應用列錶也找不到它,這就需要重新恢複該包名的可用性,這時它是不會自啟的。可通過adb命令測試:
禁用程序:adb shell pm disable com.xxx.xxx
恢複程序:adb shell pm enable com.xxx.xxx
至於代碼實現,就是通過java 發送shell指令,參考如下:
public static boolean RootCommand(String command)
{
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("sh");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
}
}
return true;
}
//調用
RootCommand("pm disable com.xxx.xxx");
這樣就可以徹底幹掉後臺頑固進程,不過切記禁用後記得及時恢複該包名的可用性。
边栏推荐
- Pulsar open source message queue_ Understand pulsar --- pulsar work notes 001
- 集群聊天服务器为什么引入负载均衡器
- Synchro esp32c3 Hardware Configuration Information serial port Print Output
- 实验设计
- Openlayers instances advanced mapbox vector tiles advanced mapbox vector maps
- 大学数据库创建与查询实战——数据库表设计
- 开源分布式链路追踪对比
- Basic syntax of MySQL DDL and DML and DQL
- Use Gaode map JS API 2.0 to load the starting and ending path tracks
- &9 nodemon自动重启工具
猜你喜欢

Cluster chat server: creation of project directory

Cmake learning

Jedis 6 - Introduction and difference between redisson and jedis

jedis 6---redisson和jedis的入门和不同

Practice data Lake iceberg lesson 37 kakfa write the enfour, not enfour test of iceberg's icberg table

University database creation and query practice -- database table design

lambda學習(sort後面的Comparator的使用,collection後使用Collectors.groupingBy分組)

实验设计

Construction and application progress of ten billion level knowledge map of meituan brain

NLP field history most complete must read classic papers classification, sorting and sharing (with Chinese analysis)
随机推荐
合宙ESP32C3硬件配置信息串口打印輸出
js 对象数组去重
What is Kai Niu? Excuse me, is it safe to open a stock account by mobile phone?
Still have 1 requests outstanding when connection from slaveX/X.X.X.X:33202 is closed
Sixty final review questions of software architecture
C——文件
Use Gaode map JS API 2.0 to load the starting and ending path tracks
节流和防抖的说明和实现
Cluster chat server: Framework Design of model data layer and encapsulation of database code
二分函数细节
Hezhou esp32c3 hardware configuration information serial port printout
JS object array de duplication
博客总排名为918
U++学习笔记 基础人物轴绑定及映射绑定
Yushu A1 robot dog gesture control
Complete set of official openlayers instances
pulsar开源消息队列_了解Pulsar---Pulsar工作笔记001
ApplicationContext introduction
机器学习习题——对率回归
SQL注入攻击