2014-02-24 41 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

相關問題