日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android應(yīng)用程序進(jìn)程啟動過程的源代碼分析(四)

上文中的函數(shù)將創(chuàng)建進(jìn)程的參數(shù)放到argsForZygote列表中去。

專注于為中小企業(yè)提供網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)萬州免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

如參數(shù)"--runtime-init"表示要為新創(chuàng)建的進(jìn)程初始化運(yùn)行時(shí)庫,然后調(diào)用zygoteSendAndGetPid函數(shù)進(jìn)一步操作。

Step 4. Process.zygoteSendAndGetPid

這個(gè)函數(shù)定義在frameworks/base/core/java/Android/os/Process.java文件中:

 
 
  1. [java] view plaincopypublic class Process { 
  2.   ...... 
  3.   private static int zygoteSendArgsAndGetPid(ArrayList args) 
  4.   throws ZygoteStartFailedEx { 
  5.   int pid; 
  6.   openZygoteSocketIfNeeded(); 
  7.   try { 
  8.   /** 
  9.   * See com.android.internal.os.ZygoteInit.readArgumentList() 
  10.   * Presently the wire format to the zygote process is: 
  11.   * a) a count of arguments (argc, in essence) 
  12.   * b) a number of newline-separated argument strings equal to count 
  13.   * 
  14.   * After the zygote process reads these it will write the pid of 
  15.   * the child or -1 on failure. 
  16.   */ 
  17.   sZygoteWriter.write(Integer.toString(args.size())); 
  18.   sZygoteWriter.newLine(); 
  19.   int sz = args.size(); 
  20.   for (int i = 0; i < sz; i++) { 
  21.   String arg = args.get(i); 
  22.   if (arg.indexOf('\n') >= 0) { 
  23.   throw new ZygoteStartFailedEx( 
  24.   "embedded newlines not allowed"); 
  25.   } 
  26.   sZygoteWriter.write(arg); 
  27.   sZygoteWriter.newLine(); 
  28.   } 
  29.   sZygoteWriter.flush(); 
  30.   // Should there be a timeout on this? 
  31.   pid = sZygoteInputStream.readInt(); 
  32.   if (pid < 0) { 
  33.   throw new ZygoteStartFailedEx("fork() failed"); 
  34.   } 
  35.   } catch (IOException ex) { 
  36.   ...... 
  37.   } 
  38.   return pid; 
  39.   } 
  40.   ...... 
  41.   } 
  42.   這里的sZygoteWriter是一個(gè)Socket寫入流,是由openZygoteSocketIfNeeded函數(shù)打開的: 
  43.   [java] view plaincopypublic class Process { 
  44.   ...... 
  45.   /** 
  46.   * Tries to open socket to Zygote process if not already open. If 
  47.   * already open, does nothing. May block and retry. 
  48.   */ 
  49.   private static void openZygoteSocketIfNeeded() 
  50.   throws ZygoteStartFailedEx { 
  51.   int retryCount; 
  52.   if (sPreviousZygoteOpenFailed) { 
  53.   /* 
  54.   * If we've failed before, expect that we'll fail again and 
  55.   * don't pause for retries. 
  56.   */ 
  57.   retryCount = 0; 
  58.   } else { 
  59.   retryCount = 10; 
  60.   } 
  61.   /* 
  62.   * See bug #811181: Sometimes runtime can make it up before zygote. 
  63.   * Really, we'd like to do something better to avoid this condition, 
  64.   * but for now just wait a bit... 
  65.   */ 
  66.   for (int retry = 0 
  67.   ; (sZygoteSocket == null) && (retry < (retryCount + 1)) 
  68.   ; retry++ ) { 
  69.   if (retry > 0) { 
  70.   try { 
  71.   Log.i("Zygote", "Zygote not up yet, sleeping..."); 
  72.   Thread.sleep(ZYGOTE_RETRY_MILLIS); 
  73.   } catch (InterruptedException ex) { 
  74.   // should never happen 
  75.   } 
  76.   } 
  77.   try { 
  78.   sZygoteSocket = new LocalSocket(); 
  79.   sZygoteSocket.connect(new LocalSocketAddress(ZYGOTE_SOCKET, 
  80.   LocalSocketAddress.Namespace.RESERVED)); 
  81.   sZygoteInputStream 
  82.   = new DataInputStream(sZygoteSocket.getInputStream()); 
  83.   sZygoteWriter = 
  84.   new BufferedWriter( 
  85.   new OutputStreamWriter( 
  86.   sZygoteSocket.getOutputStream()), 
  87.   256); 
  88.   Log.i("Zygote", "Process: zygote socket opened"); 
  89.   sPreviousZygoteOpenFailed = false; 
  90.   break; 
  91.   } catch (IOException ex) { 
  92.   ...... 
  93.   } 
  94.   } 
  95.   ...... 
  96.   } 
  97.   ...... 
  98.   } 

這個(gè)Socket由frameworks/base/core/java/com/android/internal/os/ZygoteInit.java文件中的ZygoteInit類在runSelectLoopMode函數(shù)偵聽的。


分享文章:Android應(yīng)用程序進(jìn)程啟動過程的源代碼分析(四)
瀏覽路徑:http://www.5511xx.com/article/dpdoosh.html