title: How to get PID of java.lang.Process in linux by JAVA
body: <p>I think out two method to resolve this question but they can't reach the expectation .</p>
  <ol>
  <li><p>I use the 'Process' to exec &quot;ps -ef&quot;</p>
  <p>I can through this method to get all lines and I can filter them by my running
  command.But If I have many same command process.This isn't work.</p>
  </li>
  <li><p>I use the JNA to get PID</p>
  </li>
  </ol>
  <pre><code>
  
      Field field = null;
      Integer pid = -1;
      try {
          Class clazz = Class.forName("java.lang.UNIXProcess");
          field = clazz.getDeclaredField("pid");
          field.setAccessible(true);
          pid = (Integer) field.get(process);
      } catch (Throwable e) {
          e.printStackTrace();
      }
  
  </code></pre>
  <p>This way only can get the PID of running window. It isn't the true PID of process.</p>
  <p>what should I do?</p>
  <p>Thanks!</p>