int (Process process) { String processClassName = process.getClass().getName(); if (processClassName.equals("java.lang.Win32Process") || processClassName.equals("java.lang.ProcessImpl")) { try { if (JavaVersion.current().feature >= 9) { return ((Long)Process.class.getMethod("pid").invoke(process)).intValue(); } else { long handle = Objects.requireNonNull(ReflectionUtil.getField(process.getClass(), process, long.class, "handle")); return Kernel32.INSTANCE.GetProcessId(new WinNT.HANDLE(Pointer.createConstant(handle))); } } catch (Throwable t) { throw new IllegalStateException("Failed to get PID from instance of " + process.getClass() + ", OS: " + SystemInfo.OS_NAME, t); } } throw new IllegalStateException("Unable to get PID from instance of " + process.getClass() + ", OS: " + SystemInfo.OS_NAME); }