Re: How to determime process name from pid?
Re: How to determime process name from pid?
- Subject: Re: How to determime process name from pid?
- From: Chaskiel M Grundman <email@hidden>
- Date: Mon, 19 Nov 2001 12:43:34 -0500 (EST)
Based on reading ps sources:
#include <sys/sysctl.h>
int mib[4];
struct kinfo_proc p;
int bufSize;
mib[0]=CTL_KERN;
mib[1]=KERN_PROC;
mib[2]=KERN_PROC_PID;
mib[3]=the_pid;
bufSize=sizeof(p);
error=sysctl(mib,4, &p, &bufSize, NULL, 0);
if error is 0, the data you want is in p->ki_p->p_comm
This is a non-privileged operation.