1
我有一些进程的PID,需要获取父进程ID。如何使用目标c获取它?如何在OS X中使用objective c获取父进程ID?
我有一些进程的PID,需要获取父进程ID。如何使用目标c获取它?如何在OS X中使用objective c获取父进程ID?
原始来源:http://www.objectpark.net/parentpid.html
#include <sys/sysctl.h>
#define OPProcessValueUnknown UINT_MAX
int ProcessIDForParentOfProcessID(int pid)
{
struct kinfo_proc info;
size_t length = sizeof(struct kinfo_proc);
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
if (sysctl(mib, 4, &info, &length, NULL, 0) < 0)
return OPProcessValueUnknown;
if (length == 0)
return OPProcessValueUnknown;
return info.kp_eproc.e_ppid;
}
信贷,信贷是由于:http://stackoverflow.com/questions/14162059/mac-osx-how-to-know-if-app-automatically-launched- at-session-startup-login – trojanfoe
这是从我正在工作的一个项目的代码库,其中的来源被引用为http://www.objectpark.net/parentpid.html,但该网站已经死了,麻烦了。 *编辑:该网站显然没有死。随你;来源补充说。 – tenfour
酷;感谢更新。 – trojanfoe