Re: [Darwin-Dev] open file descriptors for a process?
Re: [Darwin-Dev] open file descriptors for a process?
- Subject: Re: [Darwin-Dev] open file descriptors for a process?
- From: Dave Keck <email@hidden>
- Date: Mon, 30 Mar 2009 13:24:30 -1000
#include <libproc.h>
#include <sys/proc_info.h>
#include <stdlib.h>
int num_fd_for_pid(pid_t pid)
{
struct proc_fdinfo *temp_buffer;
int pidinfo_result,
result;
pidinfo_result = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
if (pidinfo_result <= 0)
return pidinfo_result;
temp_buffer = malloc(pidinfo_result);
pidinfo_result = proc_pidinfo(pid, PROC_PIDLISTFDS, 0,
temp_buffer, pidinfo_result);
free(temp_buffer);
if (pidinfo_result <= 0)
return pidinfo_result;
result = (pidinfo_result / PROC_PIDLISTFD_SIZE);
return result;
}
Just whipped that up, seems to work but no guarantees yada yada. Also,
libproc.h states:
/*
* This header file contains private interfaces to obtain process information.
* These interfaces are subject to change in future releases.
*/
_______________________________________________
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