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方法中創建進程,因為一個進程應該運行在一個虛擬機上,在這里如何能實現虛擬機的機制。
