前言
当前业务,需要写一个脚本,不断监视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`