2014-02-24 38 views

回答

1

原始来源: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; 
} 
+2

信贷,信贷是由于:http://stackoverflow.com/questions/14162059/mac-osx-how-to-know-if-app-automatically-launched- at-session-startup-login – trojanfoe

+0

这是从我正在工作的一个项目的代码库,其中的来源被引用为http://www.objectpark.net/parentpid.html,但该网站已经死了,麻烦了。 *编辑:该网站显然没有死。随你;来源补充说。 – tenfour

+0

酷;感谢更新。 – trojanfoe

相关问题