Skip to content

Instantly share code, notes, and snippets.

@jtai
Created April 17, 2013 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtai/5408684 to your computer and use it in GitHub Desktop.
Save jtai/5408684 to your computer and use it in GitHub Desktop.
Java program to print out open / max file descriptors
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.Method;
class Descriptors {
public static void main(String [ ] args) {
OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
try {
Method getMaxFileDescriptorCountField = osMxBean.getClass().getDeclaredMethod("getMaxFileDescriptorCount");
Method getOpenFileDescriptorCountField = osMxBean.getClass().getDeclaredMethod("getOpenFileDescriptorCount");
getMaxFileDescriptorCountField.setAccessible(true);
getOpenFileDescriptorCountField.setAccessible(true);
System.out.println(getOpenFileDescriptorCountField.invoke(osMxBean) + "/" + getMaxFileDescriptorCountField.invoke(osMxBean));
} catch (Exception e) {}
}
}
@witbrock
Copy link

witbrock commented May 7, 2014

This is very useful - used it to diagnose a limit of 4096 file descriptors on a Linux system that claims its limit is 2.4 million.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment