Re: how to get the pid from ps



On 2006-07-26, john_woo@xxxxxxxxxx wrote:
Hi,

the output from ps -ef | grep my.jar is:

root 2343 1 0 Jul27 ? 00:00:00
/usr/java/jdk1.5.0_06/bin/java -classpath /usr/local/my.jar: com.Server
/usr/local/logger.property
root 4194 2969 0 01:36 pts/1 00:00:00 grep my.jar

I'm wondering, how to get the 2343 and how to know no such program
running?

I'v tried ps -ef | grep my.jar | cut -f1,2,3 -d' ' but it output:

Remove multiple spaces:

ps -ef | grep '[m]y.jar' | tr -s ' ' | cut -f1,2,3 -d' '

Also, most modern versions of ps allow you to select which fields
you want printed:

ps -eo user,pid,gid,comm | grep '[m]y.jar'

root
root


Toronto

Ditto.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • Re: Getting the file name
    ... Thought the file name would be $i, but printing that gives me the grep ... A Problem-Solution Approach (2005, Apress) ...
    (comp.unix.shell)
  • Re: find a file containing two words in different lines
    ... Use grep -l to greate a list containing one of the words, ... Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ...
    (comp.unix.shell)
  • Re: help : cat help | grep ^99d dont work
    ... On 2006-12-02, key9 wrote: ... grep '^99' ... A Problem-Solution Approach (2005, Apress) ...
    (comp.unix.shell)
  • Re: Command substitution
    ... need grep: ... A Problem-Solution Approach, 2005, Apress ...
    (comp.unix.shell)
  • Re: while read line
    ... one starts with fixedStep, etc, the other one is a number, such as ... grep: fixedStep: No such file or directory ... Use case to check whether a string contains another string: ... A Problem-Solution Approach (2005, Apress) ...
    (comp.unix.shell)