Android_系统进程解析

Android系统启动后由一系列进程维护整个系统的运行,所有操作系统都有进程的概念,那么了解一个系统程序,就必须得先解析它所有的进程,通过这些内存中的进程就可以构建操作系统的梁柱,从进程入手则一览众山小,由此开枝散叶展开对整个系统的了解和学习。

好了废话不多说,至于进程的概念,我猿类自然懂得。 ~_~

下面是Android系统启动流程简略图:

Android系统启动流程图

进程篇—进程整理

查看进程

使用如下命令获取进程打印到文件

1
2
adb shell ps -p > D:\process.md  
adb shell ps -p -t -P > D:\process.md

下面是我获取的Android进程列表,其中包括进程ID,进程NAME等一系列信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
USER      PID   PPID  VSIZE  RSS  PRIO  NICE  RTPRI SCHED  WCHAN            PC  NAME
root 1 0 23068 1408 20 0 0 0 SyS_epoll_ 00000000 S /init
root 2 0 0 0 20 0 0 0 kthreadd 00000000 S kthreadd
root 3 2 0 0 20 0 0 0 smpboot_th 00000000 S ksoftirqd/0
root 5 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/0:0H
root 7 2 0 0 20 0 0 0 rcu_gp_kth 00000000 S rcu_preempt
root 8 2 0 0 20 0 0 0 rcu_gp_kth 00000000 S rcu_sched
root 9 2 0 0 20 0 0 0 rcu_gp_kth 00000000 S rcu_bh
root 10 2 0 0 -100 0 99 1 smpboot_th 00000000 S migration/0
root 11 2 0 0 -100 0 99 1 __kthread_ 00000000 R migration/1
root 12 2 0 0 20 0 0 0 __kthread_ 00000000 R ksoftirqd/1
root 14 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/1:0H
root 15 2 0 0 -100 0 99 1 __kthread_ 00000000 R migration/2
root 16 2 0 0 20 0 0 0 __kthread_ 00000000 R ksoftirqd/2
root 18 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/2:0H
root 19 2 0 0 -100 0 99 1 __kthread_ 00000000 R migration/3
root 20 2 0 0 20 0 0 0 __kthread_ 00000000 R ksoftirqd/3
root 22 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/3:0H
root 23 2 0 0 0 -20 0 0 rescuer_th 00000000 S khelper
root 24 2 0 0 0 -20 0 0 rescuer_th 00000000 S perf
root 25 2 0 0 0 -20 0 0 rescuer_th 00000000 S writeback
root 26 2 0 0 0 -20 0 0 rescuer_th 00000000 S crypto
root 27 2 0 0 0 -20 0 0 rescuer_th 00000000 S bioset
root 28 2 0 0 0 -20 0 0 rescuer_th 00000000 S kblockd
root 29 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 30 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_task
root 31 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_resource
root 32 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 33 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 34 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 35 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 36 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 37 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 38 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 39 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 40 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 41 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 42 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 43 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 44 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 45 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 46 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 47 2 0 0 0 -20 0 0 rescuer_th 00000000 S cmdq_auto_relea
root 48 2 0 0 0 -20 0 0 rescuer_th 00000000 S emi_mpu
root 50 2 0 0 0 -20 0 0 rescuer_th 00000000 S cfg80211
root 51 2 0 0 -99 0 98 1 pmic_threa 00000000 S pmic_thread
root 52 2 0 0 -100 0 99 1 cpufreq_in 00000000 S cfinteractive
root 53 2 0 0 20 0 0 5 ion_heap_d 00000000 S ion_mm_heap
root 54 2 0 0 20 0 0 5 ion_heap_d 00000000 S ion_mm_heap_for
root 69 2 0 0 20 0 0 0 kswapd 00000000 S kswapd0
root 70 2 0 0 20 0 0 0 fsnotify_m 00000000 S fsnotify_mark
root 71 2 0 0 20 0 0 0 fuse_iolog 00000000 S fuse_log
root 92 2 0 0 -100 0 99 1 _mt_gpufre 00000000 S mt_gpufreq_inpu
root 93 2 0 0 -98 0 97 1 _hps_task_ 00000000 D hps_main
root 94 2 0 0 0 -20 0 0 rescuer_th 00000000 S mtk_vibrator
root 95 2 0 0 0 -20 0 0 rescuer_th 00000000 S accdet
root 96 2 0 0 0 -20 0 0 rescuer_th 00000000 S accdet_disable
root 98 2 0 0 0 -20 0 0 rescuer_th 00000000 S accdet_eint
root 99 2 0 0 0 -20 0 0 rescuer_th 00000000 S usb20_st_wq
root 100 2 0 0 20 0 0 0 kthread 00000000 D ddp_irq_log_kth
root 101 2 0 0 -88 0 87 2 msleep 00000000 D display_esd_che
root 102 2 0 0 -88 0 87 2 primary_di 00000000 S display_recover
root 103 2 0 0 -88 0 87 2 decouple_m 00000000 S decouple_update
root 104 2 0 0 -88 0 87 2 decouple_t 00000000 D decouple_trigge
root 105 2 0 0 20 0 0 0 dpmgr_wait 00000000 S display_check_a
root 106 2 0 0 -88 0 87 2 _present_f 00000000 S present_fence_w
root 107 2 0 0 -88 0 87 2 primary_di 00000000 S frame_update_wo
root 108 2 0 0 20 0 0 0 primary_di 00000000 D disp_idlemgr
root 109 2 0 0 20 0 0 5 ion_heap_d 00000000 S ion_fb_heap
root 111 2 0 0 0 -20 0 0 rescuer_th 00000000 S ged_notify_sw_v
root 114 2 0 0 20 0 0 0 btif_rx_th 00000000 S btif_rxd
root 115 2 0 0 0 -20 0 0 rescuer_th 00000000 S bcct_chrlmt_wor
root 116 2 0 0 -100 0 99 1 msleep 00000000 D hang_detect
root 117 2 0 0 0 -20 0 0 rescuer_th 00000000 S sf_wk_main
root 118 2 0 0 0 -20 0 0 rescuer_th 00000000 S mbim_ether
root 119 2 0 0 0 -20 0 0 rescuer_th 00000000 S mbim_ether_rx1
root 120 2 0 0 0 -20 0 0 rescuer_th 00000000 S uether
root 121 2 0 0 0 -20 0 0 rescuer_th 00000000 S uether_rx1
root 122 2 0 0 0 -20 0 0 rescuer_th 00000000 S dm_bufio_cache
root 123 2 0 0 0 -20 0 0 rescuer_th 00000000 S msdc-tune
root 124 2 0 0 20 0 0 0 mmc_queue_ 00000000 S mmcqd/0
root 125 2 0 0 20 0 0 0 mmc_queue_ 00000000 S mmcqd/0boot0
root 126 2 0 0 20 0 0 0 mmc_queue_ 00000000 S mmcqd/0boot1
root 127 2 0 0 20 0 0 0 mmc_queue_ 00000000 S mmcqd/0rpmb
root 128 2 0 0 -51 0 50 1 irq_thread 00000000 S irq/259-1113000
root 129 2 0 0 0 -20 0 0 rescuer_th 00000000 S binder
root 131 2 0 0 0 -20 0 0 rescuer_th 00000000 S ipv6_addrconf
root 132 2 0 0 0 -20 0 0 rescuer_th 00000000 S deferwq
root 133 2 0 0 20 0 0 0 ptp_volt_t 00000000 S PTP_CTRL_MCUSYS
root 134 2 0 0 0 -20 0 0 rescuer_th 00000000 S sensor_polling
root 135 2 0 0 0 -20 0 0 rescuer_th 00000000 S hwmsen_polling
root 136 2 0 0 0 -20 0 0 rescuer_th 00000000 S stk_ps_tune0_wq
root 137 2 0 0 0 -20 0 0 rescuer_th 00000000 S accel_polling
root 139 2 0 0 0 -20 0 0 rescuer_th 00000000 S f_mtp
root 140 2 0 0 20 0 0 0 sleep_thre 00000000 S file-storage
root 141 2 0 0 0 -20 0 0 rescuer_th 00000000 S mtk-tpd
root 142 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/3:1H
root 143 2 0 0 0 -20 0 0 rescuer_th 00000000 S gt1x_workthread
root 144 2 0 0 -5 0 4 2 tpd_event_ 00000000 S mtk-tpd
root 145 2 0 0 0 -20 0 0 rescuer_th 00000000 S touch_resume
root 146 2 0 0 20 0 0 0 bat_thread 00000000 D bat_thread_kthr
root 147 2 0 0 20 0 0 0 charger_hv 00000000 S mtk charger_hv_
root 148 2 0 0 0 -20 0 0 rescuer_th 00000000 S mt-wdk
root 149 2 0 0 -100 0 99 1 msleep_int 00000000 S wdtk-0
root 150 2 0 0 -100 0 99 1 msleep_int 00000000 S wdtk-1
root 151 2 0 0 -100 0 99 1 msleep_int 00000000 S wdtk-2
root 152 2 0 0 -100 0 99 1 msleep_int 00000000 S wdtk-3
root 153 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/2:1H
root 154 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/1:1H
root 155 1 11244 1292 20 0 0 0 poll_sched 00000000 S /sbin/ueventd
root 157 2 0 0 20 0 0 0 kjournald2 00000000 S jbd2/mmcblk0p18
root 158 2 0 0 0 -20 0 0 rescuer_th 00000000 S ext4-rsv-conver
root 159 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/0:1H
root 167 2 0 0 20 0 0 0 kjournald2 00000000 S jbd2/mmcblk0p20
root 168 2 0 0 0 -20 0 0 rescuer_th 00000000 S ext4-rsv-conver
root 172 2 0 0 20 0 0 0 kjournald2 00000000 S jbd2/mmcblk0p19
root 173 2 0 0 0 -20 0 0 rescuer_th 00000000 S ext4-rsv-conver
root 177 2 0 0 20 0 0 0 kjournald2 00000000 S jbd2/mmcblk0p3-
root 178 2 0 0 0 -20 0 0 rescuer_th 00000000 S ext4-rsv-conver
root 182 2 0 0 20 0 0 0 kjournald2 00000000 S jbd2/mmcblk0p4-
root 183 2 0 0 0 -20 0 0 rescuer_th 00000000 S ext4-rsv-conver
root 187 2 0 0 20 0 0 0 kjournald2 00000000 S jbd2/mmcblk0p13
root 188 2 0 0 0 -20 0 0 rescuer_th 00000000 S ext4-rsv-conver
logd 190 1 23612 3628 18 -2 0 3 sigsuspend 00000000 S /system/bin/logd
root 195 2 0 0 20 0 0 0 kauditd_th 00000000 S kauditd
root 199 1 23648 2056 20 0 0 0 hrtimer_na 00000000 S /system/bin/vold
root 208 1 11044 540 20 0 0 0 SyS_epoll_ 00000000 S /sbin/healthd
system 211 1 12160 1016 20 0 0 0 poll_sched 00000000 S /vendor/bin/wmt_launcher
system 213 1 12048 1028 20 0 0 0 hrtimer_na 00000000 S /system/bin/memsicp
radio 214 1 78608 1248 20 0 0 0 ccci_fs_io 00000000 S /vendor/bin/ccci_fsd
system 216 1 15244 1412 20 0 0 0 ccci_vir_c 00000000 S /vendor/bin/ccci_mdinit
root 219 1 13824 1496 -2 0 1 1 SyS_epoll_ 00000000 S /system/bin/lmkd
system 220 1 13072 1432 20 0 0 0 binder_thr 00000000 S /system/bin/servicemanager
system 221 1 98224 4896 12 -8 0 0 SyS_epoll_ 00000000 S /system/bin/surfaceflinger
shell 222 1 11932 852 20 0 0 0 n_tty_read b55b989c S /system/bin/sh
root 223 1 16260 1532 20 0 0 0 hrtimer_na 00000000 S /system/bin/wland
system 224 1 15796 1316 20 0 0 0 sigsuspend 00000000 S /vendor/bin/mobile_log_d
root 225 2 0 0 20 0 0 0 osal_wait_ 00000000 S mtk_stp_psm
shell 226 1 13980 1088 20 0 0 0 futex_wait 00000000 S /vendor/bin/netdiag
system 228 1 12052 1024 20 0 0 0 __skb_recv 00000000 S /vendor/bin/sysenv_daemon
system 229 1 19688 1576 20 0 0 0 binder_thr 00000000 S /vendor/bin/pq
system 231 1 31644 1896 20 0 0 0 binder_thr 00000000 S /vendor/bin/aal
root 232 1 17576 1484 20 0 0 0 binder_thr 00000000 S /vendor/bin/dm_agent_binder
mediacodec 235 1 42956 2064 20 0 0 0 binder_thr 00000000 S media.codec
root 236 2 0 0 20 0 0 0 osal_wait_ 00000000 S mtk_stp_btm
gps 237 1 53432 1216 20 0 0 0 futex_wait 00000000 S /vendor/bin/mtk_agpsd
gps 238 1 68244 980 20 0 0 0 futex_wait 00000000 S /vendor/bin/slpd
root 239 2 0 0 20 0 0 0 osal_threa 00000000 S mtk_wmtd
root 240 1 17472 1428 20 0 0 0 binder_thr 00000000 S /vendor/bin/GoogleOtaBinder
system 242 1 17512 1496 20 0 0 0 binder_thr 00000000 S /vendor/bin/nvram_agent_binder
system 244 1 12992 1128 20 0 0 0 poll_sched 00000000 S /vendor/bin/thermal
system 245 1 14164 1364 20 0 0 0 hrtimer_na 00000000 S /vendor/bin/thermald
system 246 1 14688 1344 20 0 0 0 futex_wait 00000000 S /vendor/bin/fuelgauged
shell 247 1 14036 1300 20 0 0 0 hrtimer_na b68d6730 S /vendor/bin/batterywarning
system 249 1 16936 1404 20 0 0 0 binder_thr 00000000 S /vendor/bin/MtkCodecService
gps 250 1 32120 1712 20 0 0 0 futex_wait 00000000 S /vendor/bin/mnld
wifi 251 1 11984 1164 20 0 0 0 poll_sched 00000000 S /vendor/bin/wifi2agps
root 252 1 69836 4308 20 0 0 0 binder_thr 00000000 S /system/bin/fpserver
system 253 1 51568 2432 20 0 0 0 binder_thr 00000000 S /system/bin/fingerprintd
root 254 1 1008652 27824 20 0 0 0 poll_sched 00000000 S zygote
audioserver 255 1 43632 3184 20 0 0 0 binder_thr 00000000 S /system/bin/audioserver
root 256 2 0 0 0 -20 0 0 rescuer_th 00000000 S fm_timer_wq
root 257 2 0 0 0 -20 0 0 rescuer_th 00000000 S fm_eint_wq
cameraserver 259 1 164536 3744 20 0 0 0 binder_thr 00000000 S /system/bin/cameraserver
drm 260 1 56124 2620 20 0 0 0 binder_thr 00000000 S /system/bin/drmserver
root 261 1 13172 1456 20 0 0 0 unix_strea 00000000 S /system/bin/installd
keystore 262 1 15840 1716 20 0 0 0 binder_thr 00000000 S /system/bin/keystore
media 263 1 42928 4660 20 0 0 0 binder_thr 00000000 S /system/bin/mediadrmserver
mediaex 265 1 61576 2108 20 0 0 0 binder_thr 00000000 S media.extractor
media 266 1 64444 2208 20 0 0 0 binder_thr 00000000 S /system/bin/mediaserver
root 267 1 32968 2184 20 0 0 0 binder_thr 00000000 S /system/bin/netd
system 275 1 17936 1408 20 0 0 0 binder_thr 00000000 S /vendor/bin/program_binary_service
system 276 1 32172 1784 20 0 0 0 binder_thr 00000000 S /system/bin/gatekeeperd
root 291 1 15388 1284 20 0 0 0 hrtimer_na 00000000 S /system/xbin/perfprofd
shell 382 1 27020 720 20 0 0 0 poll_sched 00000000 S /sbin/adbd
root 384 1 12160 1100 20 0 0 0 poll_sched 00000000 S /vendor/bin/stp_dump3
shell 446 1 15744 1536 20 0 0 0 pipe_wait acad08c8 S /vendor/bin/mdlogger
radio 447 1 27416 1216 20 0 0 0 hrtimer_na 00000000 S /vendor/bin/gsm0710muxd
root 489 1 14752 1680 0 -20 0 0 poll_sched 00000000 S /system/bin/debuggerd
radio 528 1 58592 1672 20 0 0 0 hrtimer_na 00000000 S /vendor/bin/mtkrild
radio 602 1 52896 1884 20 0 0 0 hrtimer_na 00000000 S /vendor/bin/rilproxy
system 694 254 1178084 83460 20 0 0 0 SyS_epoll_ 00000000 S system_server
u0_a29 939 254 898948 68800 20 0 0 0 SyS_epoll_ 00000000 S com.android.systemui
media_rw 955 199 15504 1212 20 0 0 0 inotify_re 00000000 S /system/bin/sdcard
root 1146 2 0 0 20 0 0 0 tx_thread 00000000 S tx_thread
wifi 1199 1 16308 2388 20 0 0 0 poll_sched 00000000 S /system/bin/wpa_supplicant
radio 1213 254 893756 42004 20 0 0 0 SyS_epoll_ 00000000 S com.android.phone
u0_a15 1440 254 818456 19436 20 0 0 0 SyS_epoll_ 00000000 S com.google.android.ext.services
u0_a14 1507 254 1039656 73420 20 0 0 0 SyS_epoll_ 00000000 S com.google.android.gms.persistent
u0_a30 1530 254 1177992 21792 20 0 0 0 SyS_epoll_ 00000000 S com.google.android.googlequicksearchbox:interactor
system 1544 254 825868 21528 20 0 0 0 SyS_epoll_ 00000000 S com.transsion.statisticalsales
u0_a1 1556 254 827544 19872 20 0 0 0 SyS_epoll_ 00000000 S com.android.contacts
system 1571 254 828164 24756 20 0 0 0 SyS_epoll_ 00000000 S com.transsion.tpoint
u0_a29 1586 254 822624 25204 20 0 0 0 SyS_epoll_ 00000000 S com.reallytek.weather
system 1710 254 830820 24712 20 0 0 0 SyS_epoll_ 00000000 S com.transsion.phonemanager
u0_a14 1778 254 1120460 70320 20 0 0 0 SyS_epoll_ 00000000 S com.google.android.gms
root 1809 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/1:1
root 2288 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/u8:0
u0_a61 2414 254 832684 25528 20 0 0 0 SyS_epoll_ 00000000 S com.android.inputmethod.latin
root 2601 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/0:0
root 2749 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/0:1
root 2767 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/u8:3
root 2770 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/2:0
u0_a14 2798 254 828448 28976 20 0 0 0 SyS_epoll_ 00000000 S com.google.process.gapps
root 2823 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/u9:0
u0_a14 2878 254 954364 44324 20 0 0 0 SyS_epoll_ 00000000 S com.google.android.gms.unstable
system 2912 254 827156 25492 20 0 0 0 SyS_epoll_ 00000000 S com.android.deskclock
shell 2991 382 12724 1396 20 0 0 0 0 aca9989c R ps
system 3351 254 823604 25192 20 0 0 0 SyS_epoll_ 00000000 S com.rlk.powersavemanagement
u0_a108 3892 254 892964 47380 20 0 0 0 SyS_epoll_ 00000000 S com.emoji.keyboard.touchpal
u0_a21 3990 254 1166496 61156 20 0 0 0 SyS_epoll_ 00000000 S com.transsion.hilauncher
root 25295 2 0 0 0 -20 0 0 rescuer_th 00000000 S fs_suspend_syss
u0_a24 25566 254 1032516 38124 20 0 0 0 SyS_epoll_ 00000000 S com.android.vending
root 30018 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/2:2
root 30940 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/3:2
root 31363 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/1:2
root 31383 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/3:0
root 31508 2 0 0 20 0 0 0 worker_thr 00000000 S kworker/2:1
u0_a10 32016 254 825788 28712 20 0 0 0 SyS_epoll_ 00000000 S android.process.media
root 32417 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/u9:2

进程解析

  • root 1 0 23068 1408 20 0 0 0 SyS_epoll_ 00000000 S /init

Android情景分析之详解init进程

Android的init过程(二):初始化语言(init.rc)解析

从linux看Android之一–init进程

init进程由Linux内核启动,是Android系统的第一个进程,其主要任务如下:

1、创建与内核相关的目录(如:设备驱动文件:/deb,内存文件:/proc,/sys)
2、初始化属性服务
3.处理配置文件中的命令(主要:init.rc),包括处理各种Action
4、性能分析(使用bootchart工具)
5、无限循环执行command(启动其他进程,如:zygote)

  • root 254 1 1008652 27824 20 0 0 0 poll_sched 00000000 S zygote

Android系统进程Zygote启动过程的源代码分析

zygote进程主要功能如下:

1、系统启动时init进程会创建Zygote进程,Zygote进程负责后续Android应用程序框架层的其它进程的创建和启动工作。
2、Zygote进程会首先创建一个SystemServer进程,SystemServer进程负责启动系统的关键服务,如包管理服务PackageManagerService和应用程序组件管理服务ActivityManagerService。
3、当我们需要启动一个Android应用程序时,ActivityManagerService会通过Socket进程间通信机制,通知Zygote进程为这个应用程序创建一个新的进程。

  • root 2 0 0 0 20 0 0 0 kthreadd 00000000 S kthreadd

关于kthreadd

kthreadd是守护进程, 主要是管理kworker进程(创建kworkder进程, 所以发现kworker的 parent pid都为2), 并且始终处于内核态

  • root 5 2 0 0 0 -20 0 0 worker_thr 00000000 S kworker/0:0H

kworker全写(kernel worker)

linux系统的内核工作进程, 负责中断处理, 定时器, I/O等工作, kworkder后面的数字表明自己运行在哪个CPU的哪个核上

  • root 128 2 0 0 -51 0 50 1 irq_thread 00000000 S irq/259-1113000

irq全写(Interrupt Requesting)

即终端处理程序, 负责各种终端任务的处理工作, 来实现系统的多任务处理. 至于irq后面字符的意义, 就要查询代码了

  • root 3 2 0 0 20 0 0 0 smpboot_th 00000000 S ksoftirqd/0

软中断

软中断与函数调用的主要区别在于:

软中断是linux系统原“底半处理”的升级,在原有的基础上发展的新的处理方式,以适应多cpu 、多线程的软中断处理。

软中断是实现系统API函数调用的手段

函数调用时将返回地址和CPU状态寄存器内容压栈,函数执行完毕后出栈返回断点继续执行。

软中断调用时将返回地址和CPU状态寄存器内容压栈,修改特权级,根据中断号查找中断向量表,找到ISR中断服务例程地址,跳转执行。

综上,函数调用和软中断调用的区别是,软中断多了修改特权级和查找中断向量表的功能,其他部分完全一样。

  • root 10 2 0 0 -100 0 99 1 smpboot_th 00000000 S migration/0

what-is-the-migration-process

migration (移民) 进程主要作用就是在CPU核上移动任务作为负载均衡(每个核心上至少有1个migration进程), 它是 kernel process

  • root 23 2 0 0 0 -20 0 0 rescuer_th 00000000 S khelper

khelper进程主要是kernel进程与userspace进程交互的辅助进程,如下代码可知

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* This is run by khelper thread  */  
static void __call_usermodehelper(struct work_struct *work)
{
struct subprocess_info *sub_info =
container_of(work, struct subprocess_info, work);
int wait = sub_info->wait & ~UMH_KILLABLE;
pid_t pid;

/* CLONE_VFORK: wait until the usermode helper has execve'd
* successfully We need the data structures to stay around
* until that is done. */
if (wait == UMH_WAIT_PROC)
pid = kernel_thread(wait_for_helper, sub_info,
CLONE_FS | CLONE_FILES | SIGCHLD);
else
pid = kernel_thread(____call_usermodehelper, sub_info,
CLONE_VFORK | SIGCHLD);

switch (wait) {
case UMH_NO_WAIT:
call_usermodehelper_freeinfo(sub_info);
break;

case UMH_WAIT_PROC:
if (pid > 0)
break;
/* FALLTHROUGH */
case UMH_WAIT_EXEC:
if (pid < 0)
sub_info->retval = pid;
umh_complete(sub_info);
}
}