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