zoukankan      html  css  js  c++  java
  • android,JNI创建进程,使用fork()

    long add(long x,long y)
    {
        pid_t fpid; //fpid表示fork函数返回的值  
        int count=0;  
        fpid=fork();   
        if (fpid < 0)   
            LOGI("error in fork!");   
        else if (fpid == 0) {  
            LOGI("i am the child process, my process id is %d/n",getpid());       
            count++;  
            return x;
        }  
        else {  
            LOGI("i am the parent process, my process id is %d/n",getpid());   
            count++;  
            return y;
        } 
    }
    

     JNI调用native 方法 add函数

    父进程输出了打印信息,子进程没有反应。

    父进程pid  17247

    DDMS中查看Threads,

    TID  Status   utime   stime  Name

    17247 Native  19        12     main

    adb shell ps命令查看

    USER       PID   PPID   VSZ     RSS  STAT  NAME                 

    root       152  1              S    zygote

    u0_a66   17247  152   297120  44096  S  com.example.jni

    u0_a66   17520  17247  0    0    Z  com.example.jni

    貌似android的应用程序进程都由zygote进程创建

    子进程确实创建了,但是没有运行,占用的内存为0(VZS,RSS),处于僵尸状态。

    Z :该程序应该已经终止,但是其父程序却无法正常的终止他,造成 zombie (疆尸) 程序的状态

    说明android应该不支持在JNI的native方法中创建进程,因为一个进程应该运行在一个虚拟机上,在这里如何能实现虚拟机的机制。

  • 相关阅读:
    B-Tree(B树)原理及C++代码实现
    Select(快速选择顺序统计量)原理及C++代码实现
    BucketSort(桶排序)原理及C++代码实现
    RadixSort(基数排序)原理及C++代码实现
    CountingSort(计数排序)原理及C++代码实现
    面向对象之封装
    今日算法题
    面向对象之抽象类和接口
    面向对象之多态
    今日算法题
  • 原文地址:https://www.cnblogs.com/mlj318/p/4535218.html
Copyright © 2011-2022 走看看