title: How to capture the result of a system call in a shell variable?
body: <p>We want to build a script that run every night (kills and restart a java process).  For that we need to capture the process number (since there could be more than one java process running).  The command below is basically what we will use to obtain the processes number, probably with a regexp at the end of the grep.  Unless any better suggestions comes up.</p>
  
  <pre><code>root#ps -e |grep  'java'
  18179 pts/0    00:00:43 java
  </code></pre>
  
  <p>We want to know how to parse the output above and get it into a shell variable so we can use the kill command as below.</p>
  
  <pre><code>kill -9 ${processid}
  wait 10
  </code></pre>
  
  <p>Note1: The reason we cannot rely on the normal service stop command is because the processes sometimes does not want to die.  And we have to use the kill command manually.</p>