File descriptors open info

Jonathan I. Kamens jik at athena.mit.edu
Thu Feb 28 05:24:08 AEST 1991


  I assume that you mean you want to find out from outside the particular
process.  If you're inside it, you can do something like run fchmod or fstat
on each file descriptor and count the number that succeed -- that's the number
of valid file descriptors for that process (well, actually, you have to add
to that the number that fail because of errors other than EBADF).

  From outside the process, you have to grovel in kernel memory, although some
flavors of Unix provide things like /dev/proc that allow you access to a
device that you can pull process information from.  I think SunOS has a
library of function calls whose names start with kvm_ that allow you to dig
around the kernel.

  A good way to find out how to do this on many different systems would
probably be to get your hands on the source code for "ofiles" and stare at it
for a while.  Ofiles does this, so you should be able to figure out how.

  Ofiles is available in volume 18 of the comp.sources.unix archives (make
sure you get ofiles,new, not ofiles).

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.questions mailing list