我正在尝试在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
获取的父流程ID是相同的。
我错过了什么吗?
答案 0 :(得分:3)
您无法获取自iOS 9以来其他进程的信息。sysctl
现已进行沙盒处理。您只能在iDevice 以前的iOS 9 或模拟器中执行此操作。
sysctl()检索具有适当权限的进程的系统信息
不允许iOS应用查看正在运行的其他应用
在iOS 9中,沙箱现在阻止进程访问kern.proc, 其他进程的kern.procargs和kern.procargs2值
见: