I can get the total numbers of currently active and allocated file descriptors in Solaris os using the command:

echo ::kmastat | sudo mdb -k| grep file_cache

But the mdb requires super user privilege.

Is there any command that can do the same task without super user privilege? Or is it even possible?

OS info: Oracle Solaris 11.4 X86

  • Can you use kstat -n file_cache? And perhaps you can look into the 'new' sstore command which provides access to the stats store. – Lambert Nov 1 '19 at 13:06
  • Why? What are you going to do with the number you get? If you need performance numbers, just configure sar and use the reports from it. – Andrew Henle Nov 3 '19 at 16:15

By definition, it is not possible to run a command that adds up open files, as root-owned files are not visible to a normal user (unless they have the required permissions, which would defeat the object).

You'd have to actively defeat root privacy, and add the user to the sudoers file (Solaris > ver 11) to run the mdb command, or add the user to a group that has read access to root-owned files.

See Why file-nr and lsof count on open files differs? for info on file handler count vs listing open "files" - the totals differ, depending on folders counted as files etc.

For Solaris you can count open files by process... or you need to be able to view root files, and then use "lsof":

lsof | wc -l

For individual processes, you can run "pfiles" against the PID. See thegeekdiary for more.

However, perhaps try using ps and then pfiles:

ps -A | awk '{print $1}' | xargs pfiles

Then add up the totals with awk.

I also tried to use find, but it's a mess as it lists sockets etc. too:

find /proc/*/fd/ * -type f | grep -v "Permission denied" | wc -l
  • Ok, got it. But in ubuntu we can read the detail from the file /proc/sys/fs/file-nr. Is there a file something like this for solaris?? – Prabhakar Tayenjam Nov 1 '19 at 12:36
  • No, not to my knowledge. You have to list the open files and count them. Added detail to answer above. – sarlacii Nov 1 '19 at 13:11
  • Added hack using ps and pfiles. Works better than trying to use find to count fd links in proc dir. Thoughts? – sarlacii Nov 1 '19 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.