Created
April 17, 2013 23:44
-
-
Save jtai/5408684 to your computer and use it in GitHub Desktop.
Java program to print out open / max file descriptors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.