应用程序在 pclose 时崩溃
Application crashing on pclose
我有一个使用 popen
解析命令行输出的应用程序。但是,在 Android 上测试时,它会在 pclose
上崩溃:为什么?在其他 Unix 环境中测试时我没有错误...
char commandLine[256] = "ps -A | grep -c myApplication";
FILE * fPipe = popen(commandLine, "r");
if (fPipe == NULL)
return 0;
int count = -1;
fscanf(fPipe, "%d", &count);
///If here I print count, I get zero, which is correct...
pclose(fPipe); ///Here it crashes!
return count;
更新: 看来使用 popen
无论如何都会导致我的应用程序在稍后阶段崩溃,就好像执行此调用会杀死我的应用程序一样。
popen
uses fork
which apparently shouldn't be used in Android. To see which processes are running probably the only safe way is to check in the /proc
dir. More reading: popen on android NDK
我有一个使用 popen
解析命令行输出的应用程序。但是,在 Android 上测试时,它会在 pclose
上崩溃:为什么?在其他 Unix 环境中测试时我没有错误...
char commandLine[256] = "ps -A | grep -c myApplication";
FILE * fPipe = popen(commandLine, "r");
if (fPipe == NULL)
return 0;
int count = -1;
fscanf(fPipe, "%d", &count);
///If here I print count, I get zero, which is correct...
pclose(fPipe); ///Here it crashes!
return count;
更新: 看来使用 popen
无论如何都会导致我的应用程序在稍后阶段崩溃,就好像执行此调用会杀死我的应用程序一样。
popen
uses fork
which apparently shouldn't be used in Android. To see which processes are running probably the only safe way is to check in the /proc
dir. More reading: popen on android NDK