Android的BUG(四) - Android app的卡死问题
做android,免不了要去运行一些跑分程序,常用的跑分程序有quadrant(象限),nbench,安兔兔等。作为系统工程师,对这些跑分 程序都非常的不屑,这个只能是一个不客观的参考,但客户都喜欢拿这个比较,于是乎,各家各厂都或多或少会针对此做优化(甚至是作弊或直接的作假),这可不 是什么好现象,浮夸的厉害,到处放卫星,亩产万斤的,弄的我们这些老实人都很被动。不过这里就不说这些破事了。国内大家常用的跑分程序,就是安兔兔了,但 是不知道大家有没有发现,安兔兔跑起来后,有时会卡住不动,除了返回键和触摸操作都没什么用。
出现这一问题时,home键可以退出,继续运行其他应用,说明系统此时还是正常的。Top,vmstat看一下,也没有高CPU/IO占用率的进程,ps –t看一下,也没发现D状态的线程。不过,<span style="ps –t倒是发现了一个现象:
app_47 9691 8787 610076 28768 ffffffff 2aac4424 S com.antutu.ABenchMark
app_47 9706 9691 609060 24476 80061b00 2aac5434 S com.antutu.ABenchMark
出现了同名的进程!这很奇怪~
看这两个进程的父进程, 一个是zygote, 另外一个,则是com.antutu.ABenchMark自己。由此大约可以推断出来,后一个进程是前一个进程fork出来的,fork后还没来得及exec就卡住了。
接上adb,看下两个进程的状态吧:
Process: 9691
(gdb) bt
#0 read () at bionic/libc/arch-mips/syscalls/read.S:13
#1 0x2ad6d7d0 in executeProcess (env=0x1c7e60, javaCommands=0x2c118ab8, javaEnvironment=0x0, javaWorkingDirectory=0x0, inDescriptor=0x2c118af0, outDescriptor=0x2c118b00,
errDescriptor=0x2c118b10, redirectErrorStream=0 '\000') at libcore/luni/src/main/native/java_lang_ProcessManager.cpp:165
#2 ProcessManager_exec (env=0x1c7e60, javaCommands=0x2c118ab8, javaEnvironment=0x0, javaWorkingDirectory=0x0, inDescriptor=0x2c118af0, outDescriptor=0x2c118b00,
errDescriptor=0x2c118b10, redirectErrorStream=0 '\000') at libcore/luni/src/main/native/java_lang_ProcessManager.cpp:240
#3 0x2b8cccc4 in call_it () at external/libffi/src/mips/o32.S:145
#4 0x0026eb78 in ?? ()
没什么特别的,确实是卡在process的fork中。
再看看process 9706
(gdb) info thread
* 1 Thread 9706 __futex_syscall4 () at bionic/libc/arch-mips/bionic/atomics_mips.S:218
(gdb) bt
#0 __futex_syscall4 () at bionic/libc/arch-mips/bionic/atomics_mips.S:218
#1 0x2aabc288 in _normal_lock (mutex=0x2ab2142c) at bionic/libc/bionic/pthread.c:951
#2 pthread_mutex_lock (mutex=0x2ab2142c) at bionic/libc/bionic/pthread.c:1041
#3 0x2aabf848 in dlmalloc (bytes=4096) at bionic/libc/bionic/dlmalloc.c:4261
#4 0x2aace004 in __smakebuf (fp=0x2ab21598) at bionic/libc/stdio/makebuf.c:62
#5 0x2aad4658 in __swsetup (fp=0x2ab21598) at bionic/libc/stdio/wsetup.c:73
#6 0x2aace6a0 in putc_unlocked (c=48, fp=<value optimized out>) at bionic/libc/stdio/putc.c:46
#7 0x2aace744 in putc (c=48, fp=0x2ab21598) at bionic/libc/stdio/putc.c:64
#8 0x2aae44c0 in cpuacct_add (uid=<value optimized out>) at bionic/libc/bionic/cpuacct.c:55
#9 0x2aae57b0 in fork () at bionic/libc/bionic/fork.c:57
#10 0x2ad6d764 in executeProcess (env=0x1c7e60, javaCommands=0x2c118ab8, javaEnvironment=0x0, javaWorkingDirectory=0x0, inDescriptor=0x2c118af0, outDescriptor=0x2c118b00,
errDescriptor=0x2c118b10, redirectErrorStream=0 '\000') at libcore/luni/src/main/native/java_lang_ProcessManager.cpp:92
#11 ProcessManager_exec (env=0x1c7e60, javaCommands=0x2c118ab8, javaEnvironment=0x0, javaWorkingDirectory=0x0, inDescriptor=0x2c118af0, outDescriptor=0x2c118b00,
errDescriptor=0x2c118b10, redirectErrorStream=0 '\000') at libcore/luni/src/main/native/java_lang_ProcessManager.cpp:240
#12 0x2b8cccc4 in call_it () at external/libffi/src/mips/o32.S:145
#13 0x0026eb78 in ?? ()
(gdb)
可以看到停在bionic的fork中了,具体函数是: cpuacct_add(getuid()); 中的fprintf。 错误原因从bt上看得到,又是锁的问题。
这个问题找到原因后,解决方法倒是没有花什么精力,直接google一下,问题和解决方法都出来了:
https://code.google.com/p/android/issues/detail?id=19916
Comment 1 by gabrb...@gmail.com, Nov 23, 2011 This issue has also been found on ICS. cpuacct_add should not be doing anything that calls malloc() or free(). Proposed fixes are here:
http://review.omapzoom.org/16579 http://review.omapzoom.org/16573
现在越来越多的apk,会偷偷的fork进程,执行系统中的命令或dump调试信息,甚至如skype,会一下fork很多自己写的native服务,看着总归不是很爽。
版权声明:本文为博主原创文章,未经博主允许不得转载。
相关文章
- Android 插件化 动态升级
- [Android Pro] Android权限设置android.permission完整列表
- 【黑马Android】(02)短信发送器/布局演示/android下单位/android下Junit/保存数据/android下权限/xml解析和序列化
- android MVP框架
- Android开发之旅:android架构
- Android API之android.widget.Filterable
- Android API之android.provider.ContactsContract.Data
- Android API之android.view.View.MeasureSpec
- bug -- android 7.0 popwindow显示位置异常情况解决
- bug_ _ android.view.InflateException: Binary XML file line #2: Error inflating class <unknown
- bug_ _ _android.app.Fragment$InstantiationException 解决办法
- 安卓Android手机直播推送同步录像功能设计与实现源码
- 《android开发艺术探索》读书笔记(八)--WindowManager
- Android开发者指南(26) —— Resource Types - Layout
- Android:轮播图ViewPager自动轮播最简单方法
- android 编程规范 check list
- Android问题笔记 - TBS如何真正意义上彻底离线使用
- Android图像艺术 drawable技巧解决图片引发的内存和适配
- Android 4.4 如何禁止显示通知
- android显示系统
- Android 几种设置ImageView的图片的方法
- Android kotlin 系列讲解(数据篇)SharedPreferences存储及测试
- Android报错提示:Failed to resolve: com.android.support.constraint:constraint-layout:1.1.3
- Android File文件复制功能实现
- Android 10.0 SystemUI设置导航栏默认为系统手势导航
- Android 9.0 10.0 去掉开机提示 android is starting 的对话框
- Android 进入其他app和退出App杀死进程的方法详解
- android 获取生肖和星座
- Android 中 C++ Thread线程用法(五十七)
- Android Studio下“Error:Could not find com.android.tools.build:gradle:2.2.1”的解决方法
- Android Studio 4.2.2 Kotlin的import kotlinx.android.synthetic.main.(layout的xml名).view.*
- 如何解决Android Studio的import android.support.v7.widget.RecyclerView的RecyclerView标红问题
- android开发,Android Studio Build Output 输出的中文显示乱码
- 迁移到Android后android.support.v4.content.FileProvider运行崩溃