Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cbmvax!uunet!bria!mike From: mike@bria.commodore.com Newsgroups: comp.unix.questions Subject: Re: File descriptors open info Message-ID: <487@bria> Date: 28 Feb 91 01:23:50 GMT References: <1991Feb26.213145.26540@batcomputer.tn.cornell.edu> Reply-To: uunet!bria!mike Organization: MGI Group International, Los Angeles, CA Lines: 33 Followup-To: Keywords: In an article, theory.tn.cornell.edu!hurf (Hurf Sheldon) writes: >is there a Unix system call (or some other method) for >finding out how many file descriptors a process has >open? Well, the *real* way to do this is to go munging through the kernel's process table. :-) Actually, you could do something like this: #define MAXFD 100 /* or some reasonable number */ getnumfd() { int i = 0, num = 0; struct stat buf; while ( i < MAXFD ) if ( fstat(i++,&buf) == 0 ) ++num; return num; } Kind of ugly, but it could get the job done. The only drawback is that the MAXFD value may be unrealistic after a few "relinkings of the kernel." Cheers, -- Michael Stefanik, MGI Inc., Los Angeles| Opinions stated are not even my own. Title of the week: Systems Engineer | UUCP: ...!uunet!bria!mike ------------------------------------------------------------------------------- Remember folks: If you can't flame MS-DOS, then what _can_ you flame?