Re: per process file attributes
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com It will probably not be helpful. My advice is to parse the output. -- Terry Manish -----Original Message----- From: Terry Lambert [mailto:tlambert@apple.com] Sent: Thursday, March 20, 2008 11:24 AM To: Manish Chaturvedi Cc: darwin-kernel@lists.apple.com 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 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 (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/tlambert%40apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... If you do, you need to be willing to update your application every time we do a software update of any kind, just like we have to be prepared to update ps, lsof, and anything else that uses SPI any time we do a Software Update. Most vendors like to keep their application from breaking every month or so, though, since SPI can (and does) change all the time. The bright spot is that we update those things that depend on SPI in lock-step with software updates, so things like lsof, ps, netstat, and so on keep working. Generally, people are happier talking to the programs that use SPI (and stay working between updates) than they are talking to SPI (even if that means having to parse program output). It means they don't have support calls and suffer being broken a couple of weeks during which they scramble to fix their application to use the new SPI for their irate customers. This gets even more complicated if you specify a release target, since the SDK headers are not updated as a result of an OS SU, rather only as a result of an XCode SU. The XCode and OS schedules usually don't sync up, so you'll be using the wrong header files until they do, if you end up using an SDK. So unless you are working from the xnu and/ or utility sources for something that already knows how to output what you are trying to generate, you won't necessarily have the internal headers you need until the sources post, which is yet more time you will be broken. On Mar 19, 2008, at 11:08 PM, Manish Chaturvedi wrote: 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? On Mar 19, 2008, at 10:36 PM, Manish Chaturvedi wrote: This email sent to tlambert@apple.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Terry Lambert