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

前言

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

脚本

#!/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. 一个shell脚本进入pod服务运行命令

    2024-07-09 20:16:02       45 阅读
  2. 导出docker MySQL中的数据库一个shell 脚本

    2024-07-09 20:16:02       45 阅读
  3. shell_结束进程脚本

    2024-07-09 20:16:02       34 阅读
  4. shell脚本变量

    2024-07-09 20:16:02       30 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-09 20:16:02       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-09 20:16:02       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-09 20:16:02       90 阅读
  4. Python语言-面向对象

    2024-07-09 20:16:02       98 阅读

热门阅读

  1. SSL 证书

    2024-07-09 20:16:02       35 阅读
  2. HP打印机Er报错 (重新开始或恢复按钮 ↓)

    2024-07-09 20:16:02       26 阅读
  3. php简单实现利用飞书群里机器人推送消息的方法

    2024-07-09 20:16:02       29 阅读
  4. 终于弄明白了什么是EI!

    2024-07-09 20:16:02       26 阅读
  5. 期货量化交易:探索金融投资的新领域

    2024-07-09 20:16:02       31 阅读
  6. 探索金融数据API:现代投资的关键工具

    2024-07-09 20:16:02       30 阅读
  7. uniApp 封装VUEX

    2024-07-09 20:16:02       25 阅读
  8. H5与小程序:两者有何不同?

    2024-07-09 20:16:02       28 阅读
  9. 论文引用h指数

    2024-07-09 20:16:02       35 阅读