0

我试图在 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 因此是一个错误。如果我向当前进程getppid()询问其kp_eproc.e_ppid.
我错过了什么吗?

4

1 回答 1

3

由于iOS 9.现在是沙盒,您无法获取其他进程的信息。sysctl您只能在iOS 9 之前的 iDevice或模拟器中执行此操作。

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

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

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

看:

于 2016-12-15T03:15:38.913 回答