List of usage examples for java.lang Process getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.nifi.bootstrap.RunNiFi.java
private Long getPid(final Process process, final Logger logger) { try {//from w ww . ja va2 s . c o m final Class<?> procClass = process.getClass(); final Field pidField = procClass.getDeclaredField("pid"); pidField.setAccessible(true); final Object pidObject = pidField.get(process); logger.debug("PID Object = {}", pidObject); if (pidObject instanceof Number) { return ((Number) pidObject).longValue(); } return null; } catch (final IllegalAccessException | NoSuchFieldException nsfe) { logger.debug("Could not find PID for child process due to {}", nsfe); return null; } }
From source file:la2launcher.MainFrame.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); int srow = jTable1.getSelectedRow(); if (srow < 0) { return;// w w w .j a va2 s.c o m } Integer procid = (Integer) dtm.getValueAt(srow, 0); for (Process proc : procs) { if ((proc.hashCode() + "").equals(procid.toString())) { try { Field field = proc.getClass().getDeclaredField("handle"); if (!field.isAccessible()) { field.setAccessible(true); } long pid = field.getLong(proc); Kernel32 kernel = Kernel32.INSTANCE; W32API.HANDLE handle = new W32API.HANDLE(); handle.setPointer(Pointer.createConstant(pid)); long pid_ = kernel.GetProcessId(handle); User32 u32 = User32.INSTANCE; u32.EnumWindows(new WinUser.WNDENUMPROC() { @Override public boolean callback(WinDef.HWND hwnd, Pointer pntr) { char[] windowText = new char[512]; u32.GetWindowText(hwnd, windowText, 512); String wText = Native.toString(windowText); if (wText.isEmpty()) { return true; } if (wText.equals("Lineage II")) { //TODO: 111 IntByReference pid__ = new IntByReference(); u32.GetWindowThreadProcessId(hwnd, pid__); if ((pid__.getValue() + "").equals(pid_ + "")) { u32.SetForegroundWindow(hwnd); lastHWND = hwnd; } } return true; } }, null); } catch (NoSuchFieldException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalArgumentException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:org.apache.nifi.minifi.bootstrap.RunMiNiFi.java
private Long getPid(final Process process, final Logger logger) { try {/*from w ww.j a v a 2 s . c o m*/ final Class<?> procClass = process.getClass(); final Field pidField = procClass.getDeclaredField(PID_KEY); pidField.setAccessible(true); final Object pidObject = pidField.get(process); logger.debug("PID Object = {}", pidObject); if (pidObject instanceof Number) { return ((Number) pidObject).longValue(); } return null; } catch (final IllegalAccessException | NoSuchFieldException nsfe) { logger.debug("Could not find PID for child process due to {}", nsfe); return null; } }