【android】【adb shell】写一个shell脚本,监听进程pid变化

前言

当前业务,需要写一个脚本,不断监视com.android.phone 进程是否异常死掉

脚本

bash 复制代码
#!/system/bin/sh
last_pid=""
current_pid=""
while(true){
	current_pid=`ps -A | grep com.android.phone | awk '{print $2}'`
	if [ -n "$current_pid" ]; then

		if [ "$current_pid" != "$last_pid" ]; then  
			echo "PID changed from $last_pid to $current_pid"  
		fi  

		last_pid=$current_pid  
	else  
		echo "Failed to get PID for com.android.phone"  
	fi
	echo $current_pid
sleep 1
}

测试

复制代码
// 获取phone pid并kill
kill -9 `pidof com.android.phone`
相关推荐
_祝你今天愉快1 天前
Android 事件传递机制:[二] 手写模拟事件分发
android
东坡大表哥1 天前
【Ubuntu】Ubuntu 20.04 LTS → 22.04 LTS 升级实录
android·linux·ubuntu
不要试图纠正别人2 天前
IdleHandler 一次都不跑,问题不在主线程忙
android·性能优化
booboosui2 天前
记忆装不下时谁删:500 条上限与每回合十行索引
android
好的佩奇2 天前
Dart 之 JSON
android·flutter·dart
_祝你今天愉快2 天前
Android 事件传递机制:[一] 事件分发机制详解
android
Digitally2 天前
如何将电脑上的联系人传输到安卓手机(4 种方法)
android
Carson带你学Android3 天前
移动开发周报 :一句话出 App、低端机跑 Gemini、手机写代码
android·ai编程
恋猫de小郭3 天前
站起来,Flutter 要支持真正的 3D Texture 了
android·前端·flutter
FungLeo3 天前
FengCMS · PHP+MySQL 升级实录 · 留言模块的六项问题:未审核进公开列表、旧回复覆盖、批量删除恢复
android·mysql·php·工程实践·fengcms