【问题标题】:Application crashing on pclose应用程序在 pclose 上崩溃
【发布时间】:2015-03-02 17:15:39
【问题描述】:

我有一个使用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 会导致我的应用程序在稍后阶段崩溃,就好像执行此调用会杀死我的应用程序一样。

【问题讨论】:

标签: android c linux file-io pipe


【解决方案1】:

popen uses fork 显然是shouldn't be used in Android。要查看哪些进程正在运行,可能唯一安全的方法是签入/proc 目录。更多阅读:popen on android NDK

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多