Re: Path to executable of current process?

看板FB_hackers作者時間18年前 (2007/07/24 11:06), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/5 (看更多)
> Is there any way to get argv[0] for [a particular] process without being root? After more digging I see sysctl seems to be the way to do this but can I get the full path to the executable form kinfo_proc? How does ps do this? static const char * getcmdline(pid_t pid) { static struct kinfo_proc ki_proc; int mib[4], len; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = pid; len = sizeof(struct kinfo_proc); if (sysctl(mib, 4, &ki_proc, &len, NULL, 0) == -1) return NULL; return ki_proc.ki_??? } Mike _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
文章代碼(AID): #16fMom00 (FB_hackers)
文章代碼(AID): #16fMom00 (FB_hackers)