【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·c++·算法
奔跑吧 android2 小时前
【android bluetooth 协议分析 12】【A2DP详解 1】【车机侧蓝牙音乐免切源介绍】
android·bluetooth·bt·gd·a2dpsink·免切源·aosp14
飞猿_SIR3 小时前
Android Exoplayer多路不同时长音视频混合播放
android·音视频
前端懒猫4 小时前
android实现USB通讯
android
jiet_h4 小时前
Android锁
android
VirusVIP5 小时前
Windows CMD通过adb检查触摸屏Linux驱动是否被编译
linux·运维·adb
teacher伟大光荣且正确13 小时前
Qt Creator 配置 Android 编译环境
android·开发语言·qt
飞猿_SIR15 小时前
Android Exoplayer 实现多个音视频文件混合播放以及音轨切换
android·音视频
HumoChen9916 小时前
GZip+Base64压缩字符串在ios上解压报错问题解决(安卓、PC模拟器正常)
android·小程序·uniapp·base64·gzip
didiplus19 小时前
MySQL 8.0 OCP(1Z0-908)英文题库(31-40)
mysql·adb·ocp·数据库管理员·mysql认证