Link to home
Start Free TrialLog in
Avatar of checkin
checkin

asked on

How many file open ?

Hi !

How can I find out how many file descriptors a process has open ?  Either I can use a system call but preferrably I would like to put it in the program itself.  I am on Sun Solaris machine.

Marvin.
Avatar of ozo
ozo
Flag of United States of America image

You could try scaning the __iob[] structure.
ASKER CERTIFIED SOLUTION
Avatar of kejin
kejin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kejin
kejin

Sorry, ozo, I didn't see you already post a comment.
Also, to ozo, my understanding is, __iob[]  only includes fds opened via fopen() , fdopen() and fdopen(). Other fds opened through open(), pipe(), dup(), socket(), accept(),  etc.. are not included.
code correction:

the last code line in the proposed answer:

     return count -3;

should change to:

     if( pid == getpid() )
        return count - 3;
     else
        return count -2;