init.rc
1.
app_process是通过下面这个文件编译出来的,
在./frameworks/base/cmds/app_process/app_main.cpp中
其中class AppRuntime : public AndroidRuntime,所以上面的start就是调用AndroidRuntime的start
a.运行的进程是app_process为什么看到的却是zygote呢?
set_process_name
--> prctl(PR_SET_NAME, (unsigned long) new_name, 0, 0, 0); ;;system/core/libcutils/process_name.c
将进程的名字改为zygote了
2.
在./frameworks/base/core/jni/AndroidRuntime.cpp中
- service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
- class main
- socket zygote stream 660 root system
- onrestart write /sys/android_power/request_state wake
- onrestart write /sys/power/state on
- onrestart restart media
- onrestart restart netd
1.
app_process是通过下面这个文件编译出来的,
在./frameworks/base/cmds/app_process/app_main.cpp中
- int main(int argc, const char* const argv[])
- {
- //将进程名改为zygote
- if (niceName && *niceName) {
- setArgv0(argv0, niceName);
- set_process_name(niceName);
- }
- //调用AndroidRuntime的start
- AppRuntime runtime;
- runtime.addVmArguments(argc, argv);
- runtime.mParentDir = parentDir;
- runtime.start("com.android.internal.os.ZygoteInit", "start-system-server" );
- }
a.运行的进程是app_process为什么看到的却是zygote呢?
set_process_name
--> prctl(PR_SET_NAME, (unsigned long) new_name, 0, 0, 0); ;;system/core/libcutils/process_name.c
将进程的名字改为zygote了
2.
在./frameworks/base/core/jni/AndroidRuntime.cpp中
- void AndroidRuntime::start(const char* className, const char* options)
- {
- if (strcmp(options, "start-system-server") == 0)
- const int LOG_BOOT_PROGRESS_START = 3000;
-
- JNIEnv* env;
- startVm(&mJavaVM, &env); //创建java虚拟机
- --> JNI_CreateJavaVM
-
- onVmCreated(env);
-
- startReg(env);
-
- //将 "com.android.internal.os.ZygoteInit", "start-system-server"都放在strArray中
- ...
-
- //找到"com.android.internal.os.ZygoteInit"这个类
- char* slashClassName = toSlashClassName(className);
- jclass startClass = env->FindClass(slashClassName);
- //并找到"com.android.internal.os.ZygoteInit"这个类的main方法
- jmethodID startMeth = env->GetStaticMethodID(startClass, "main", "([Ljava/lang/String;)V");
- //调用"com.android.internal.os.ZygoteInit"这个类的main方法
- env->CallStaticVoidMethod(startClass, startMeth, strArray);
- }