当前位置:网站首页>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

边栏推荐
- 693. 行程排序(map + 拓扑)
- P1908 逆序对
- 【文档树、设置】字体变小
- BeanUtils--浅拷贝--实例/原理
- 使用BLoC 构建 Flutter的页面实例
- QT new project_ MyNotepad++
- Mysql5.7 installation super easy tutorial
- Partner cloud form strong upgrade! Pro version, more extraordinary!
- Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
- Verification failed, please check your call back website. You can follow the instructions
猜你喜欢

Explanation: here is your UFO, Goldbach conjecture

Browser driven Download

Common options of tcpdump command: Three

Error function ERF
![[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology](/img/a7/44609a5acf25021f1fca566c3d8c90.png)
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology

Qt-制作一个简单的计算器-实现四则运算

What are eNB, EPC and PGW?

瀏覽器驅動的下載

题解:《压缩技术》(原版、续集版)

使用BLoC 构建 Flutter的页面实例
随机推荐
[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
Use bloc to build a page instance of shutter
Use of UIC in QT
为什么switch 的default后面要跟break?
Selenium element positioning method
mysql ---- Oracle中的rownum转换成MySQL
【文档树、设置】字体变小
D为何链接不了dll
What are eNB, EPC and PGW?
Detailed collection of common MySQL commands
ensp简单入门
[usaco05jan]watchcow s (Euler loop)
SystemServer进程
BeanUtils -- shallow copy -- example / principle
Three talking about exception -- error handling
浏览器驱动的下载
Selenium, element operation and browser operation methods
Will your sleep service dream of the extra bookinfo on the service network
Performance optimization of memory function
Common options of tcpdump command: Three