list of open files for given pid
list of open files for given pid
- Subject: list of open files for given pid
- From: Tobias Hoehmann <email@hidden>
- Date: Fri, 02 Sep 2005 15:08:49 +0200
Hello,
I'd like to get a list of all open files for a given pid as I get
by invoking 'lsof -p pid'.
Using the following code-snippet should set fd as needed:
#include <kvm.h>
#include <fcntl.h>
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <sys/filedesc.h>
int main()
{
kvm_t *kd;
int cnt, pid = 100;
struct kinfo_proc *kp;
struct proc *p;
struct filedesc *fd;
kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
kp = kvm_getprocs(kd, KERN_PROC_PID, pid, &cnt);
p = kp[0].kp_eproc.e_paddr;
// up to here everything is fine, but setting fd to the proc's fd throws
// error: request for member 'p_fd' in something not a structure or union
fd = p.p_fd;
}
As of Tiger the 'struct proc' seems to be moved to an internal header file
so I can't rely on proc.p_fd's existance in upcoming os x versions...
Any idea or any other technique is appreciated as the access to /dev/mem
needs suid-exec-bit set.
Thanks
Tobias
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden