title: Find the pid of a java process under Linux
body: <p>I have a Java program running on a Linux computer, and want to find the process ID (pid) of its process. I know the <code>ps</code> command can provide this information, but its output is confusing because it has so much extraneous information. How can I get just the pid?</p>
  <hr />
  <p>I am using MPJ library in java program for Pagerank algorithm.
  I compile it by</p>
  <pre><code>javac -cp .:$MPJ_HOME/lib/mpj.jar MpiPageRank.java
  </code></pre>
  <p>and run by</p>
  <pre><code>mpjrun.sh -np 2 MpiPageRank
  </code></pre>
  <p>where <code>-np</code> is number of process</p>
  <p>Now i have to find its pid</p>
  <pre><code>ps -ef|grep java
  </code></pre>
  <p>like</p>
  <pre><code>mpjrun.sh -np 2 MpiPageRank &amp; sleep 2
  ps -ef | grep java
  </code></pre>
  <p>I get</p>
  <pre><code>pnewaska 27866 27837 99 21:28 pts/45   00:00:09 java -cp /u/pnewaska/mpj-v0_38/lib/smpdev.jar:/u/pnewaska/mpj-v0_38/lib/xdev.jar:/u/pnewaska/mpj-v0_38/lib/mpjbuf.jar:/u/pnewaska/mpj-v0_38/lib/loader2.jar:/u/pnewaska/mpj-v0_38/lib/starter.jar:/u/pnewaska/mpj-v0_38/lib/mpiExp.jar runtime.starter.MulticoreStarter /nfs/nfs1/home/pnewaska/DistributedSystems/Project3 10 smpdev useLocalLoader EMPTY MpiPageRank -i input.500k0 -n 10 -o
  </code></pre>
  <p>Now I want to extract <code>MpiPageRank</code> from only 1 linux comman to get its pid ie <code>27866</code>.
  how do i do that ?</p>