Android應用程式進程啟動過程的原始碼分析(三)

來源:互聯網
上載者:User

上文的mDriverFD是裝置檔案/dev/binder的開啟描述符,如果成功開啟了這個裝置檔案,那麼它的值就會大於等於0,因此,它的傳回值為true。

回到Process.start函數中,它調用startViaZygote函數進一步操作。

Step 3. Process.startViaZygote

這個函數定義在frameworks/base/core/java/android/os/Process.java檔案中:

 
  1. [java] view plaincopypublic class Process { 
  2. ...... 
  3. private static int startViaZygote(final String processClass, 
  4. final String niceName, 
  5. final int uid, final int gid, 
  6. final int[] gids, 
  7. int debugFlags, 
  8. String[] extraArgs) 
  9. throws ZygoteStartFailedEx { 
  10. int pid; 
  11. synchronized(Process.class) { 
  12. ArrayList argsForZygote = new ArrayList(); 
  13. // --runtime-init, --setuid=, --setgid=, 
  14. // and --setgroups= must go first 
  15. argsForZygote.add("--runtime-init"); 
  16. argsForZygote.add("--setuid=" + uid); 
  17. argsForZygote.add("--setgid=" + gid); 
  18. if ((debugFlags & Zygote.DEBUG_ENABLE_SAFEMODE) != 0) { 
  19. argsForZygote.add("--enable-safemode"); 
  20. if ((debugFlags & Zygote.DEBUG_ENABLE_DEBUGGER) != 0) { 
  21. argsForZygote.add("--enable-debugger"); 
  22. if ((debugFlags & Zygote.DEBUG_ENABLE_CHECKJNI) != 0) { 
  23. argsForZygote.add("--enable-checkjni"); 
  24. if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) { 
  25. argsForZygote.add("--enable-assert"); 
  26. //TODO optionally enable debuger 
  27. //argsForZygote.add("--enable-debugger"); 
  28. // --setgroups is a comma-separated list 
  29. if (gids != null && gids.length > 0) { 
  30. StringBuilder sb = new StringBuilder(); 
  31. sb.append("--setgroups="); 
  32. int sz = gids.length; 
  33. for (int i = 0; i < sz; i++) { 
  34. if (i != 0) { 
  35. sb.append(','); 
  36. sb.append(gids[i]); 
  37. argsForZygote.add(sb.toString()); 
  38. if (niceName != null) { 
  39. argsForZygote.add("--nice-name=" + niceName); 
  40. argsForZygote.add(processClass); 
  41. if (extraArgs != null) { 
  42. for (String arg : extraArgs) { 
  43. argsForZygote.add(arg); 
  44. pid = zygoteSendArgsAndGetPid(argsForZygote); 
  45. ...... 

這個函數將建立進程的參數放到argsForZygote列表中去,如參數"--runtime-init"表示要為新建立的進程初始化執行階段程式庫,然後調用zygoteSendAndGetPid函數進一步操作。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.