您的位置:首页 > 移动开发 > Android开发

Android培训班(14)

2010-07-24 23:51 330 查看
#200

#201 for(;;) {
#202 int nr, i, timeout = -1;
这段代码是进入死循环处理,以便这个init进程变成一个服务。

#203
#204 for (i = 0; i < fd_count; i++)
#205 ufds[i].revents = 0;
这段代码是清空每个socket的事件计数。

#206
#207 drain_action_queue();
这段代码是执行队列里的命令。

#208 restart_processes();
这句代码是用来判断那些服务需要重新启动。

#209
#210 if (process_needs_restart) {
#211 timeout = (process_needs_restart
- gettime()) * 1000;
#212 if (timeout < 0)
#213 timeout = 0;
#214 }
这段代码是用来判断那些进程启动超时。


#215
#216 #if BOOTCHART
#217 if (bootchart_count > 0) {
#218 if (timeout < 0 || timeout
> BOOTCHART_POLLING_MS)
#219 timeout =
BOOTCHART_POLLING_MS;
#220 if (bootchart_step() < 0 || --bootchart_count
== 0) {
#221 bootchart_finish();
#222 bootchart_count = 0;
#223 }
#224 }
#225 #endif
这段代码是用来计算运行性能。

#226 nr = poll(ufds, fd_count, timeout);
#227 if (nr <= 0)
#228 continue;
这段代码用来轮询几个socket是否有事件处理。

#229
#230 if (ufds[2].revents == POLLIN) {
#231 /* we got a SIGCHLD - reap and
restart as needed */
#232 read(signal_recv_fd, tmp,
sizeof(tmp));
#233 while (!wait_for_one_process(0))
#234 ;
#235 continue;
#236 }
这段代码是用来处理子进程的通讯,并且能删除任何已经退出或者杀死死进程,这样做可以保持系统更加健壮性,增强容错能力。


#237
#238 if (ufds[0].revents == POLLIN)
#239 handle_device_fd(device_fd);
这段代码是处理设备事件。

#240
#241 if (ufds[1].revents == POLLIN)
#242
handle_property_set_fd(property_set_fd);
这段代码是处理属性服务事件。

#243 if (ufds[3].revents == POLLIN)
#244 handle_keychord(keychord_fd);
这段代码是处理调试模式下的组合按键。

#245 }
#246
#247 return 0;
#248 }
#249

到这里已经分析完成init进程的主流程,后面再来详细地其它功能实现。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: