list of open files for given pid
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com User-agent: Internet Messaging Program (IMP) H3 (4.0.3) 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 (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Tobias Hoehmann