【问题标题】:Get parent process information at runtime on iOS application在 iOS 应用程序运行时获取父进程信息
【发布时间】:2017-03-06 05:54:15
【问题描述】:

我试图在 iOS 运行时获取一些进程信息,尤其是父进程名称。 虽然我能够获取当前进程名称,但似乎我不能为其父进程做同样的事情。
这是我正在做的事情:

static inline bool is_debugserver_present() {
    int                 err;
    int                 mib[4];
    struct kinfo_proc   info;
    size_t              size;

    // Initialize the flags so that, if sysctl fails for some bizarre
    // reason, we get a predictable result.

    info.kp_proc.p_flag = 0;

    // Initialize mib, which tells sysctl the info we want, in this case
    // we're looking for information about a the parent process ID.

    mib[0] = CTL_KERN;
    mib[1] = KERN_PROC;
    mib[2] = KERN_PROC_PID;
    mib[3] = getppid();

    // Call sysctl.

    size = sizeof(info);
    int n = sizeof(mib) / sizeof(*mib);
    err = sysctl(mib, n, &info, &size, NULL, 0);

    return (strncmp(info.kp_proc.p_comm, "launchd", sizeof("launchd") - 1) != 0);
}

问题是对sysctl 的调用总是返回-1,因此是一个错误。 如果我向当前进程询问kp_eproc.e_ppid,则getppid()获得的父进程ID相同。
我错过了什么吗?

【问题讨论】:

标签: ios pid bsd sysctl


【解决方案1】:

无法从 iOS 9 开始获取其他进程的信息。sysctl 现在被沙箱化了。您只能在 iDevice 以前的 iOS 9 或模拟器中执行此操作。

sysctl() 检索具有适当权限的进程的系统信息

iOS 应用不允许查看其他应用正在运行

在 iOS 9 中,沙盒现在阻止进程访问 kern.proc, 其他进程的 kern.procargs 和 kern.procargs2 值

见:

【讨论】:

    猜你喜欢
    • 2012-11-09
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-19
    • 2017-11-29
    • 1970-01-01
    相关资源
    最近更新 更多