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方法中创建进程,因为一个进程应该运行在一个虚拟机上,在这里如何能实现虚拟机的机制。

  • 相关阅读:
    2017年陕西省网络空间安全技术大赛WP
    XDCTF2014 Writeup
    TensorFlow入门测试程序
    python计算器
    CentOS安装crontab及使用方法
    在Linux 双机下自己手动实现浮动ip技术
    CentOS 7下安装配置FTP
    encodeURI 解码 编码
    jquery 消息提醒插件 toastmessage
    搭通自己的电脑与GitHub的传输通道
  • 原文地址:https://www.cnblogs.com/mlj318/p/4535218.html
Copyright © 2011-2022 走看看