【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`
相关推荐
百锦再2 分钟前
选择Rust的理由:从内存管理到抛弃抽象
android·java·开发语言·后端·python·rust·go
whatever who cares26 分钟前
在Java/Android中,List的属性和方法
android·java
让世界再也没有bug1 小时前
性能测试之使用 adb 查看设备CPU占用与数据分析
adb
油炸小波3 小时前
09-微服务原理篇(XXLJOB-幂等-MySQL)
android·mysql·微服务
果子没有六分钟3 小时前
setprop debug.hwui.profile visual_bars有什么作用
android
百***68046 小时前
MySQL四种备份表的方式
mysql·adb·oracle
键来大师6 小时前
Android15 源码关闭Selinux
android·java·framework·rk3588
Ro Jace7 小时前
三国华容道(横刀立马)移动策略
android·java·数据库·人工智能·深度学习·神经网络·游戏
Digitally8 小时前
如何将短信从安卓手机传输到电脑
android