Re: Which structure does sysctl fill when KERN_FILE parameter is given as input on Mac Os X 10.4.7?
Re: Which structure does sysctl fill when KERN_FILE parameter is given as input on Mac Os X 10.4.7?
- Subject: Re: Which structure does sysctl fill when KERN_FILE parameter is given as input on Mac Os X 10.4.7?
- From: Thorrin <email@hidden>
- Date: Fri, 28 Mar 2008 09:11:50 -0700 (PDT)
I don't have a direct answer to your problem, but
couldn't you look at the source code of lsof and see
what it does with the data?
http://www.opensource.apple.com/darwinsource/
-T
--- anukriti_shrimal
<email@hidden> wrote:
> Hi All,
>
>
>
> I am currently working on Mac Os X 10.4.7.
>
> I m trying to retrieve the list of files opened by
> a process using
> sysctl(). The code snippet that I've written is :
>
>
>
> void* pBuff = NULL ;
>
> mib[0] = CTL_KERN;
>
> mib[1] = KERN_FILE;
>
>
>
> size = sizeof(struct filedesc) ; //
> This is what I tried.
> This struct is defined in file sys/filedesc.h
>
> pBuff = malloc(size) ;
>
> while (sysctl((int *)mib, 2, pBuff,
> &size, NULL, 0) < 0)
>
> {
>
> if (errno == ENOMEM)
>
> {
>
> printf("Not
> sufficient memory allocated\n");
>
> }
>
> size *= 2 ;
>
> if ((arguments =
> realloc(pBuff, size)) == NULL)
>
> {
>
> printf("Realloc
> error\n");
>
> }
>
> printf("Error in getting
> file struct %s\n and error
> no is %d\n", strerror(errno),errno) ;
>
> }
>
>
>
> This code compiles and fills the buffer pBuff.
>
> Now my question is that the buffer pBuff should to
> mapped to which
> structure on Mac 10.4.7??
>
> I have found that it fills struct file or struct
> xfile on Free BSD. But on
> Mac Os, I've tried it with struct extern_file and
> struct filedesc, but both
> didn't work. Why are the two structs 'file' and
> 'xfile' not exposed on Mac
> 10.4.7?
>
> If none of the above, then which struct is getting
> filled by the above
> sysctl call?
>
>
>
> I know that there is an alternative way to do the
> same task, i.e., through
> lsof. But my project constraints don't let me use
> that. Also, when I saw the
> ktrace dump of lsof, I found that it also uses
> sysctl.
>
>
>
> Is there some other way to do the same task?
>
>
>
> Thanks in advance,
>
> Princess
>
>
>
>
>
> > _______________________________________________
> Do not post admin requests to the list. They will be
> ignored.
> Darwin-kernel mailing list
> (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
>
> This email sent to email@hidden
"Everyone is allergic to giant rocks hitting them in the head!"
-Thorrin's elf chick after casting a 'meteor swarm' spell ;)
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden