timg.jpg (18.26 KB, 下载次数: 1880)
下载附件 保存到相册
4 年前 上传
TIM是由腾讯公司于2016年11月发布的多平台IM客户端应用。TIM是在QQ轻聊版的基础上加入了协同办公服务的支持,可QQ号登录,以及好友、消息同步等,适合办公使用。
0.jpg (6.47 KB, 下载次数: 1882)
root@gityuan:/ # ps | grep tencent.tim u0_a146 27965 551 1230992 43964 SyS_epoll_ 00f6df4bf0 S com.tencent.tim:Daemon u0_a146 27996 551 1252492 54032 SyS_epoll_ 00f6df4bf0 S com.tencent.tim:MSF u0_a146 28364 551 1348616 89204 SyS_epoll_ 00f6df4bf0 S com.tencent.tim:mail u0_a146 31587 551 1406128 147976 SyS_epoll_ 00f6df4bf0 S com.tencent.tim
12-21 21:12:20.265 1053 1075 I am_kill : [0,4892,com.tencent.tim:Daemon,5,stop com.tencent.tim: from pid 4617] 12-21 21:12:20.272 1053 1075 I am_kill : [0,5276,com.tencent.tim:mail,2,stop com.tencent.tim: from pid 4617] 12-21 21:12:20.305 1053 1075 I am_kill : [0,4928,com.tencent.tim,2,stop com.tencent.tim: from pid 4617] 12-21 21:12:20.330 1053 1075 I am_kill : [0,4910,com.tencent.tim:MSF,0,stop com.tencent.tim: from pid 4617] 12-21 21:13:59.920 1053 1466 I am_proc_start: [0,5487,10146,com.tencent.tim:MSF,service,com.tencent.tim/com.tencent.mobileqq.app.DaemonMsfService] 12-21 21:13:59.984 1053 1604 I am_proc_start: [0,5516,10146,com.tencent.tim,content provider,com.tencent.tim/com.tencent.mqq.shared_file_accessor.ContentProviderImpl]
12-21 21:12:20.266 1053 1075 I AutoStartManagerService: MIUILOG- Reject RestartService packageName :com.tencent.tim uid : 10146 12-21 21:12:20.291 1053 1075 I AutoStartManagerService: MIUILOG- Reject RestartService packageName :com.tencent.tim uid : 10146 12-21 21:12:20.323 1053 1075 I AutoStartManagerService: MIUILOG- Reject RestartService packageName :com.tencent.tim uid : 10146 12-21 21:12:20.323 1053 1075 I AutoStartManagerService: MIUILOG- Reject RestartService packageName :com.tencent.tim uid : 10146 12-21 21:12:20.331 1053 1075 I AutoStartManagerService: MIUILOG- Reject RestartService packageName :com.tencent.tim uid : 10146 12-21 21:12:20.332 1053 1075 I AutoStartManagerService: MIUILOG- Reject RestartService packageName :com.tencent.tim uid : 10146
//启动DaemonAssistService时,callApp为空,只有通过PendingIntent方式才可能出现这种情况 12-21 21:56:54.653 3181 3195 I am_start_service: [-1,NULL,10146,com.tencent.tim:Daemon,com.tencent.tim/com.tencent.mobileqq.app.DaemonAssistService,{cmp=com.tencent.tim/com.tencent.mobileqq.app.DaemonAssistService}] 12-21 21:56:56.666 3181 3827 I am_start_service: [-1,NULL,10146,com.tencent.tim:MSF,com.tencent.tim/com.tencent.mobileqq.app.DaemonMsfService,{cmp=com.tencent.tim/com.tencent.mobileqq.app.DaemonMsfService}]
1.png (35.42 KB, 下载次数: 1868)
binder_transaction(...) { ... if (!reply && !(tr->flags & TF_ONE_WAY)) t->from = thread; else t->from = NULL; } ... }
binder_thread_read(...) { ... t_from = binder_get_txn_from(t); if (t_from) { struct task_struct *sender = t_from->proc->tsk; tr.sender_pid = task_tgid_nr_ns(sender, task_active_pid_ns(current)); } else { tr.sender_pid = 0; } ... }
2.png (14.34 KB, 下载次数: 1846)
3.png (23.56 KB, 下载次数: 1824)
root@gityuan:/ # echo 1 > /d/tracing/events/signal/enable root@gityuan:/ # echo 1 > /d/tracing/tracing_on
root@cancro/: cat /d/tracing/trace_pipe
//通过adb shell kill -9 10649, 将com.tencent.tim:Daemon进程杀掉 sh-22775 [000] d..2 18844.276419: signal_generate: sig=9 errno=0 code=0 comm=cent.tim:Daemon pid=10649 grp=1 res=0 // 线程Thread-89 将tencent.tim:MSF进程也杀掉了 Thread-89-10712 [000] dn.2 18844.340735: signal_generate: sig=9 errno=0 code=0 comm=tencent.tim:MSF pid=10669 grp=1 res=0 Binder:14682_4-14845 [000] d..2 18844.340779: signal_deliver: sig=9 errno=0 code=0 sa_handler=0 sa_flags=0 Binder:14682_1-14694 [000] d..2 18844.341418: signal_deliver: sig=9 errno=0 code=0 sa_handler=0 sa_flags=0 Binder:14682_2-14697 [000] d..2 18844.345075: signal_deliver: sig=9 errno=0 code=0 sa_handler=0 sa_flags=0 tencent.tim:MSF-14682 [000] dn.2 18844.345115: signal_deliver: sig=9 errno=0 code=0 sa_handler=0 sa_flags=
4.png (31.16 KB, 下载次数: 1805)
5.png (22.27 KB, 下载次数: 1807)
Cmd line: com.tencent.tim:Daemon "Thread-89" prio=10 tid=12 Native | group="main" sCount=1 dsCount=0 obj=0x32c07460 self=0xf3382000 | sysTid=10712 nice=-8 cgrp=bg_non_interactive sched=0/0 handle=0xee824930 | state=S schedstat=( 44972457 14188383 124 ) utm=1 stm=3 core=0 HZ=100 | stack=0xee722000-0xee724000 stackSize=1038KB | held mutexes= kernel: __switch_to+0x74/0x8c kernel: flock_lock_file_wait+0x2a4/0x318 kernel: SyS_flock+0x19c/0x1a8 kernel: el0_svc_naked+0x20/0x28 native: #00 pc 000423d4 /system/lib/libc.so (flock+8) native: #01 pc 0000195d /data/app/com.tencent.tim-1/lib/arm/libdaemon_acc.so (_Z9lock_filePc+64) ... native: #29 pc 0000191f /data/app/com.tencent.tim-1/lib/arm/libdaemon_acc.so (_Z9lock_filePc+2) native: #30 pc 0000191d /data/app/com.tencent.tim-1/lib/arm/libdaemon_acc.so (_Z9lock_filePc) native: #31 pc 0000191b /data/app/com.tencent.tim-1/lib/arm/libdaemon_acc.so (_Z18notify_and_waitforPcS_+102) ... native: #63 pc 000018d1 /data/app/com.tencent.tim-1/lib/arm/libdaemon_acc.so (_Z18notify_and_waitforPcS_+28) at com.libwatermelon.WaterDaemon.doDaemon2(Native method) at com.libwatermelon.strategy.WaterStrategy2$2.run(WaterStrategy2.java:111)
root@gityuan:/ # strace -CttTip 22829 -CttTip 22793
6.png (55.13 KB, 下载次数: 1830)
flock是Linux文件锁,用于多个进程同时操作同一个文件时,通过加锁机制保证数据的完整,flock使用场景之一,便是用于检测进程是否存在。flock属于建议性的锁,而非强制性锁,只是进程可以直接操作正被另一个进程用flock锁住的文件, 原因在于flock只检测文件是否加锁,内核并不会强制阻塞其他进程的读写操作,这便是建议性锁的内核策略。
方法原型: int flock(int fd, int operation)
//旧的MSF进程 24538 24562 D Watermelon: lock file success >> /data/user/0/com.tencent.tim/app_indicators/indicator_p2 24538 24562 E Watermelon: Watch >>>>Daemon<<<<< Daed !! 24538 24562 E Watermelon: java_callback:onDaemonDead 24538 24562 V Watermelon: onDaemonDead 24576 24576 D Watermelon: lock file success >> /data/user/0/com.tencent.tim/app_indicators/indicator_d1 24576 24576 E Watermelon: Watch >>>>Daemon<<<<< Daed !! 24576 24576 E Watermelon: process exit //新daemon进程 25103 25103 V Watermelon: initDaemon processName=com.tencent.tim:Daemon 25103 25103 E Watermelon: onDaemonAssistantCreate 25134 25134 D Watermelon: start daemon24=/data/user/0/com.tencent.tim/app_bin/daemon2 //app_d进程 25137 25137 D Watermelon: pipe read datasize >> 316 << 25137 25137 D Watermelon: indicator_self_path >> /data/user/0/com.tencent.tim/app_indicators/indicator_d1 25137 25137 D Watermelon: observer_daemon_path >> /data/user/0/com.tencent.tim/app_indicators/observer_p1 25137 25137 I Watermelon: sIActivityManager==NULL 25137 25137 I Watermelon: BpActivityManager init //新daemon 25103 25120 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_p2 25103 25120 D Watermelon: lock file success >> /data/user/0/com.tencent.tim/app_indicators/indicator_p2 25137 25137 I Watermelon: BpActivityManager init end //app_d进程 25137 25137 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_d1 25137 25137 D Watermelon: lock file success >> /data/user/0/com.tencent.tim/app_indicators/indicator_d1 //新MSF进程 25119 25119 V Watermelon: initDaemon processName=com.tencent.tim:MSF 25119 25119 V Watermelon: mConfigurations.PERSISTENT_CONFIG.PROCESS_NAME=com.tencent.tim:MSF 25119 25119 E Watermelon: onPersistentCreate 25153 25153 D Watermelon: start daemon24=/data/user/0/com.tencent.tim/app_bin/daemon2 25119 25144 D Watermelon: pipe write len=324 25159 25159 D Watermelon: pipe read datasize >> 324 << 25159 25159 D Watermelon: indicator_self_path >> /data/user/0/com.tencent.tim/app_indicators/indicator_p1 25159 25159 D Watermelon: observer_daemon_path >> /data/user/0/com.tencent.tim/app_indicators/observer_d1 25159 25159 I Watermelon: sIActivityManager==NULL 25159 25159 I Watermelon: BpActivityManager init 25119 25144 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_d2 25119 25144 D Watermelon: lock file success >> /data/user/0/com.tencent.tim/app_indicators/indicator_d2 25159 25159 I Watermelon: BpActivityManager init end //各进程进入监听就绪状态 25159 25159 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_p1 25159 25159 D Watermelon: lock file success >> /data/user/0/com.tencent.tim/app_indicators/indicator_p1 25119 25144 E Watermelon: Watched >>>>OBSERVER<<<< has been ready... 25119 25144 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_p2 25159 25159 E Watermelon: Watched >>>>OBSERVER<<<< has been ready... 25159 25159 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_d1 25137 25137 E Watermelon: Watched >>>>OBSERVER<<<< has been ready... 25137 25137 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_p1 25103 25120 E Watermelon: Watched >>>>OBSERVER<<<< has been ready... 25103 25120 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_d2
25159 25159 I Watermelon: BpActivityManager init 25119 25144 D Watermelon: start try to lock file >> /data/user/0/com.tencent.tim/app_indicators/indicator_d2 25119 25144 D Watermelon: lock file success >> /data/user/0/com.tencent.tim/app_indicators/indicator_d2
7.jpg (27.14 KB, 下载次数: 1834)
gityuan@13203:~/gityuan$ adb shell ps -t | grep -i flock u0_a146 10668 10649 1143304 85876 flock_lock 00f6e1e3d8 S Thread-85 u0_a146 10712 10669 1158552 89664 flock_lock 00f6e1e3d8 S Thread-89 u0_a146 10687 1 12768 564 flock_lock 00f73113d8 S app_d u0_a146 10717 1 12768 560 flock_lock 00f74353d8 S app_d
8.png (9.26 KB, 下载次数: 1854)
9.png (11.65 KB, 下载次数: 1894)
root@gityuan:/acct/uid_10146/pid_10649 # cat cgroup.procs 10649 //Daemon 10687 //app_d root@gityuan:/acct/uid_10146/pid_10669 # cat cgroup.procs 10669 //MSF 10717 //app_d
// 5170(MSF进程) --> 5192 --> 5201(退出) --> 5211(存活) tencent.tim:MSF-5170 [001] ...1 55659.446062: sched_process_fork: comm=tencent.tim:MSF pid=5170 child_comm=tencent.tim:MSF child_pid=519 Thread-300-5192 [000] ...1 55659.489621: sched_process_fork: comm=Thread-300 pid=5192 child_comm=Thread-300 child_pid=5201 <...>-5201 [003] ...1 55659.501074: sched_process_exec: filename=/data/user/0/com.tencent.tim/app_bin/daemon2 pid=5201 old_pid=5201 daemon2-5201 [009] ...1 55659.533492: sched_process_fork: comm=daemon2 pid=5201 child_comm=daemon2 child_pid=5211 daemon2-5201 [009] ...1 55659.535169: sched_process_exit: comm=daemon2 pid=5201 prio=120 daemon2-5201 [009] d..3 55659.535341: signal_generate: sig=17 errno=0 code=262145 comm=Thread-300 pid=5192 grp=1 res=1
10.png (21.18 KB, 下载次数: 1821)
11.png (21.62 KB, 下载次数: 1863)
TIM分别在Java层和Native层,主动向ServiceManager进程查询AMS后,获取BpActivityManager代理对象,然后继续使用框架中的IPCThreadState跟Binder驱动交互,并没有替换掉libbinder.so。
12.png (31.71 KB, 下载次数: 1803)
来源:即时通讯网 - 即时通讯开发者社区!
轻量级开源移动端即时通讯框架。
快速入门 / 性能 / 指南 / 提问
轻量级Web端即时通讯框架。
详细介绍 / 精编源码 / 手册教程
移动端实时音视频框架。
详细介绍 / 性能测试 / 安装体验
基于MobileIMSDK的移动IM系统。
详细介绍 / 产品截图 / 安装体验
一套产品级Web端IM系统。
详细介绍 / 产品截图 / 演示视频
引用此评论
引用:maobiwen 发表于 2020-01-13 11:33 能直接出个杀不死的demo吗
引用:小菜 发表于 2020-01-14 20:05 第一次回复,只因这篇文章太硬核了。
引用:DwayneZhang 发表于 2020-01-18 17:06 楼主牛皮呀,腾讯也是狠。像TIM团队不能像手Q,微信一样,直接找国产系统厂商加白名单吗
引用:青柠檬不酸 发表于 2020-07-01 16:52 初次接触,直接看这么硬核的文章,有点蒙,慢慢研究
引用:wangqi060934 发表于 2020-07-13 20:03 原文是2018年2月发表的,现在完全不适用了
引用:JackJiang 发表于 2020-07-13 20:04 还是乖乖看这篇吧:《Android保活从入门到放弃:乖乖引导用户加白名单吧(附7大机型加白示例)》
引用:wangqi060934 发表于 2020-12-25 10:51 引导式的效用不大,用户不会仔细看的
精华主题数超过100个。
连续任职达2年以上的合格正式版主
为论区做出突出贡献的开发者、版主等。
Copyright © 2014-2024 即时通讯网 - 即时通讯开发者社区 / 版本 V4.4
苏州网际时代信息科技有限公司 (苏ICP备16005070号-1)
Processed in 0.125000 second(s), 42 queries , Gzip On.