当前位置:网站首页>Systemserver process
Systemserver process
2022-07-02 13:57:00 【xhBruce】
SystemServer process
android12-release
Android The system starts
Zygote process
Zygote process fork And come
init process -> Zygote process -> system_server process
frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
frameworks/base/core/java/com/android/internal/os/Zygote.java
frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
art/runtime/native/dalvik_system_ZygoteHooks.cc
forkSystemServer().run() -> pid = Zygote.forkSystemServer() -> nativeForkSystemServer() -> com_android_internal_os_Zygote_nativeForkSystemServer -> pid = zygote::ForkCommon() -> pid = fork() -> SpecializeCommon()
/* Hardcoded command line to start the system server */
String[] args = {
"--setuid=1000",
"--setgid=1000",
"--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,1021,1023,"
+ "1024,1032,1065,3001,3002,3003,3006,3007,3009,3010,3011",
"--capabilities=" + capabilities + "," + capabilities,
"--nice-name=system_server",
"--runtime-args",
"--target-sdk-version=" + VMRuntime.SDK_VERSION_CUR_DEVELOPMENT,
"com.android.server.SystemServer",
};
ZygoteArguments parsedArgs;
SystemServer The process parameter information is uid=1000,gid=1000, The process name is
sytem_serverZygote.forkSystemServer()fork Outsystem_server process
com_android_internal_os_Zygote_nativeForkSystemServerJNIzygote::ForkCommon()Call tofork()Create a new process , use copy on write The way , This is a linux Standard method for creating processes , There will be two return. The return value is 3 Types : In parent process ,fork Returns the... Of the newly created child process pid; In subprocess ,fork return 0; When an error occurs ,fork Return negative .
When system_server After the process dies , restart zygote process .New creation system_server The process is complete ,
pid == 0Then enterhandleSystemServerProcess() Method
handleSystemServerProcess
fork() Here we are system_server The process has completed all the work created , Here we go system_server The real work of the process
handleSystemServerProcess(parsedArgs)complete system_server Process remaining work , Running on thesystem_server processProcess.setArgV0(parsedArgs.mNiceName)Current process name "system_server"performSystemServerDexOpt()perform dex Optimize operation , frominstalldTo complete- system_server perform
ZygoteInit.zygoteInit()
/** * Finish remaining work for the newly forked system server process. */
private static Runnable handleSystemServerProcess(ZygoteArguments parsedArgs) {
// set umask to 0077 so new files and directories will default to owner-only permissions.
Os.umask(S_IRWXG | S_IRWXO);
if (parsedArgs.mNiceName != null) {
Process.setArgV0(parsedArgs.mNiceName);
}
final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
if (systemServerClasspath != null) {
performSystemServerDexOpt(systemServerClasspath);
// Capturing profiles is only supported for debug or eng builds since selinux normally
// prevents it.
if (shouldProfileSystemServer() && (Build.IS_USERDEBUG || Build.IS_ENG)) {
try {
Log.d(TAG, "Preparing system server profile");
prepareSystemServerProfile(systemServerClasspath);
} catch (Exception e) {
Log.wtf(TAG, "Failed to set up system server profile", e);
}
}
}
if (parsedArgs.mInvokeWith != null) {
String[] args = parsedArgs.mRemainingArgs;
// If we have a non-null system server class path, we'll have to duplicate the
// existing arguments and append the classpath to it. ART will handle the classpath
// correctly when we exec a new process.
if (systemServerClasspath != null) {
String[] amendedArgs = new String[args.length + 2];
amendedArgs[0] = "-cp";
amendedArgs[1] = systemServerClasspath;
System.arraycopy(args, 0, amendedArgs, 2, args.length);
args = amendedArgs;
}
WrapperInit.execApplication(parsedArgs.mInvokeWith,
parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
VMRuntime.getCurrentInstructionSet(), null, args);
throw new IllegalStateException("Unexpected return from WrapperInit.execApplication");
} else {
ClassLoader cl = getOrCreateSystemServerClassLoader();
if (cl != null) {
Thread.currentThread().setContextClassLoader(cl);
}
/* * Pass the remaining arguments to SystemServer. */
return ZygoteInit.zygoteInit(parsedArgs.mTargetSdkVersion,
parsedArgs.mDisabledCompatChanges,
parsedArgs.mRemainingArgs, cl);
}
/* should never reach here */
}
ZygoteInit.zygoteInit()
ZygoteInit.nativeZygoteInit()stay AndroidRuntime.cpp in , the jni mappingRuntimeInit.applicationInit()Meso endomorph MethodAndArgsCaller.run functionmMethod.invoke()start-up SystemServer.main()
SystemServer.main
4.2 system service : from SystemServer.java Be responsible for starting and managing the whole Java framework In the service startBootstrapServices、startCoreServices、startOtherServices
Sequence diagram

边栏推荐
- D language, possible 'string plug-ins'
- Solve "sub number integer", "jump happily", "turn on the light"
- (POJ - 1308)Is It A Tree? (tree)
- How to use SAP's metadata framework (MDF) to build custom business rules?
- Android kotlin broadcast technology point
- Use of UIC in QT
- BeanUtils--浅拷贝--实例/原理
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
- qt中uic的使用
- Student course selection information management system based on ssm+jsp framework [source code + database]
猜你喜欢
![Unity small map production [2]](/img/d6/9d6556d37525b9986b74133f2a7aaa.jpg)
Unity small map production [2]

刚好1000粉丝,记录一下
![2022 zero code / low code development white paper [produced by partner cloud] with download](/img/46/92c51090e0c476df3bcffd2d11fb6d.png)
2022 zero code / low code development white paper [produced by partner cloud] with download

你知道Oracle的数据文件大小有上限么?

Qt新项目_MyNotepad++

错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”

混沌工程平台 ChaosBlade-Box 新版重磅发布

Selenium element positioning method

Origin plots thermogravimetric TG and differential thermogravimetric DTG curves

Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
随机推荐
Engineers who can't read device manuals are not good cooks
Use of UIC in QT
故事點 vs. 人天
leetcode621. task scheduler
三谈exception——错误处理
Pattern matching and regular expressions in PostgreSQL - Das
Achievements in science and Technology (27)
ensp简单入门
[youcans' image processing learning course] general contents
Add sequence number column to query results in MySQL
uniapp小程序 subPackages分包配置
Pointer from entry to advanced (1)
Getting started with QT - making a simple calculator
Launcher启动过程
Bridge of undirected graph
Qt新项目_MyNotepad++
QT - make a simple calculator - realize four operations
Word frequency statistics & sorting
What are eNB, EPC and PGW?
How to use SAP's metadata framework (MDF) to build custom business rules?