android系统的初始化过程是从那里开始呢?它在加载linux基本内核后,就开始运行一个初始化进程,叫做init进程,那么怎么样知道它是加载init进程的呢?难道上天就注定的吗?呵呵,不是的,原来是从android加载linux内核时,就设置了下面的参数:

Kernel command line: noinitrd root=/dev/nfs console=ttySAC0 init=/init nfsroot=192.168.1.103:/nfsboot ip=192.168.1.20:192.168.1.103:192.168.1.1:255.255.255.0::eth0:on

在这行命令里,就是告诉linux内核初始化完成后开始运行init进程,由于init进程就是放在系统根目录下面。而这个进程的代码,就是位于源码的目录system/core/init下面,现在就来仔细地分析这个进程到底做了什么事情,以便理解整个系统运行情况。在分析过程中,会学习很多有用知识,甚至linux编程知识。这么有用,还等什么呢?现在就开始,找到目录system/core/init/init.c代码,先从main函数开始,如下:

#001 int main(int argc, char **argv)

#002 {

#003 int device_fd = -1;

#004 int property_set_fd = -1;

#005 int signal_recv_fd = -1;

#006 int keychord_fd = -1;

#007 int fd_count;

#008 int s[2];

#009 int fd;

#010 struct sigaction act;

#011 char tmp[PROP_VALUE_MAX];

#012 struct pollfd ufds[4];

#013 char *tmpdev;

#014 char* debuggable;

#015

#016

#017 act.sa_handler = sigchld_handler;

#018 act.sa_flags = SA_NOCLDSTOP;

#019 act.sa_mask = 0;

#020 act.sa_restorer = NULL;

#021 sigaction(SIGCHLD, &act, 0);

在上面这段代码里,调用函数sigaction来设置处理子进程发送回来的关闭信号,其中SIGCHLD是设置子进程信号处理,SA_NOCLDSTOP是表示子进程结束时不要向父进程发送SIGCHLDsigchld_handler是信号SIGCHLD的处理函数。这样做的作用,就是如果父进程不等待子进程结束,子进程将成为僵尸进程(zombie)从而占用系统资源。因此需要对SIGCHLD信号做出处理,回收僵尸进程的资源,避免造成不必要的资源浪费。

---------------------------------------------------------------------------------------------------

招收条件:

1 自学能力强。

2 QQEMAIL

3 交学费1500(S3C6410的开发板)

报名方式:

1、加入QQ: 9073204,注明Android

2EMAIL:9073204@qq.com

更多相关文章

  1. linux kernel suspend Resume
  2. 内核版本与Android版本对应关系
  3. Android(安卓)Studio Error:Unable to resolve dependency for '
  4. Android开发指南-框架主题-基础知识
  5. Android(安卓)系统启动
  6. Android跨进程数据通讯-剪切板Clipboard
  7. Android开发中完全退出程序的三种方法
  8. [原]Android系统进程Zygote启动过程的源代码分析
  9. android 仿iphoneX上滑退出应用动画(三)

随机推荐

  1. Android安全论文汇集
  2. 动态加载Dex的原理
  3. MT6573默认锁屏界面修改
  4. Android Studio安装Genymotion插件
  5. [Android]《Android艺术开发探索》第一章
  6. Android 不同API版本 向后兼容
  7. android典型代码系列(二十八)------通话
  8. android framework中contexwrapper和cont
  9. android 颜色、 透明度参考表
  10. Linux与Android休眠唤醒对比(二)