RE: per process file attributes
RE: per process file attributes
- Subject: RE: per process file attributes
- From: "Manish Chaturvedi" <email@hidden>
- Date: Thu, 20 Mar 2008 11:38:04 +0530
Thanks Terry for quick reply, but using lsof in our program will make me to
parse the output, which seems to be a complicated job, is there is any
alternate solution to this. Will be helpful if I follow the source code of
lsof to do the same?
Manish
-----Original Message-----
From: Terry Lambert [mailto:email@hidden]
Sent: Thursday, March 20, 2008 11:24 AM
To: Manish Chaturvedi
Cc: email@hidden
Subject: Re: per process file attributes
The man page is cribbed from BSD, and not updated. We consider sysctl
as SPI due to not having gone through API review, and therefore both
unstable and not for use by third parties. If you need this
information, consider using "lsof".
-- Terry
On Mar 19, 2008, at 10:36 PM, Manish Chaturvedi wrote:
> Hi All,
>
> I am writing application to list all process and opened files by the
> process, where I am able to get the process information like
> Pid,ppid, path, process commadline arguments etc using sysctl()
> ( followed this link http://developer.apple.com/qa/qa2001/qa1123.html)
> .
>
> I am using the following code to get the file information about
> every process.
>
> int mib[3];
> struct extern_file *file = NULL ; // Is it the correct structure ?
>
> mib[0] = CTL_KERN;
> mib[1] = KERN_MAXFILES;
> mib[2] = 1693 ;
>
> size = sizeof(argmax) ;
>
> if (sysctl((int *)mib, 2, &argmax, &size, NULL, 0) < 0) {
> printf("No args found\n");
> printf("Error is %s\n", strerror(errno)) ;
>
> }
> else
> {
> printf("size is Given as %d\n",argmax) ; // argmax is
> giving me the correct values (i.e. count of all opened files )
> size = (size_t)argmax ;
>
> mib[0] = CTL_KERN; // Here I am resetting the mib arry
> for getting per process file information .
> mib[1] = KERN_FILE;
> mib[2] = 1693 ;//1693 ;//procList[i].kp_proc.p_pid;
>
> file =(extern_file*) malloc(argmax);
> if(file == NULL)
> {
> printf("file pointe not allocated yes\n") ;
> }
> if (sysctl((int *)mib, 3, fileNew, &size, NULL, 0) < 0)
> {
> printf("Error in getting file struct %s\n",
> strerror(errno)) ;
> }
> else
> {
> // Print file attributes
> }
>
> I want to list all file descriptors file paths and othet file
> attributes , which I am not getting with this program, Getting an
> error "Not a directory" during second sysctl call, where as getting
> the correct file count after first sysctl() call.
> In the man page of sysctl() KERN_FILE will return a file structure
> which is not at all documented ( not confirm about the structure to
> use ), there is no file structure exposed on Mac OS X (apart from
> extern_file and filedesc),
>
> I am not sure which structure to use ? is it possible to get per
> process file information using KERN_FILE?
> OS version is 10.4.7
> Thanks in advance!
>
> Regards,
> Manish.
> _______________________________________________
> 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
_______________________________________________
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