1753647 Members
6066 Online
108798 Solutions
New Discussion юеВ

#ps -ef | grep pmon

 
SOLVED
Go to solution
Jacques Carriere
Regular Advisor

#ps -ef | grep pmon

Does anyone know how to use the grep and not have the grep command listed in your selection.

7 REPLIES 7
Steven E. Protter
Exalted Contributor
Solution

Re: #ps -ef | grep pmon

Shalom,

modify to

ps -ef | grep pmon | grep -v pmon

Even more accurate

UNIX95=1
ps -C pmon

Do not set UNIX95 permenent, it breaks sd/ux

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
spex
Honored Contributor

Re: #ps -ef | grep pmon

Jacques,

ps -ef | grep pmon | grep -v grep

PCS
Jacques Carriere
Regular Advisor

Re: #ps -ef | grep pmon

grep -v grep is the correct answer . thanks guys for th equick reply.
Bill Hassell
Honored Contributor

Re: #ps -ef | grep pmon

Actually, grep -v is not the correct answer at all. ps has dozens of options that will bypass grep and give you the correct answer. Whenever you combine grep with ps, you'll potentially get a lot of unintended matches. This is because grep has no method to look at a specific field. So in your example, you will get hits for the user "upmon" or the group called "pmons34" and also hits for the process vpmon, and so on. If the output of the grep command was fed to a kill command, you would have a mess of killed processes on your hands.

ps will match the exact name of the process, regardless of whether it was started as ./pmon or /opt/pmonstuff/bin/pmon or simply pmon. It is the C option and must be temporarily enabled with UNIX95, like this:

UNIX95= ps -fC pmon

DO NOT export UNIX95 -- just use it as shown since the variable is temporary just for ps. Making UNIX95 permanent can lead to unexpected behavior of other commands. And yes, the UNIX95= is correct -- it means defined UNIX95 as a null string.

To see how unreliable ps|grep is, try these two commands to find all the shells:

ps -ef | grep -v grep | grep sh

and

UNIX95= ps -fC sh

To make life easier, I simply alias the ps command in .profile so it is always used with ps:

alias ps="UNIX95= /usr/bin/ps"

Now you can type ps and get all the special features like -H and -o, something like this:

ps -eH

ps -C pmon -o vsz,pid,ppid,ruser,args

UNIX95 (when defined even as a null variable) turns on XPG4 behavior as defined in the ps man page.


Bill Hassell, sysadmin
Procnus
Frequent Advisor

Re: #ps -ef | grep pmon

Personally I prefer a grep command like:
#ps -ef | grep p[m]on

Which letter gets the brackets around it doesn't matter, as long as only one charcter is bracketed.
spex
Honored Contributor

Re: #ps -ef | grep pmon

Jacques,

If my previous response gives false positives, use:

ps -ef | grep ora_pmon_ | grep -v grep

Whenever you grep for something, you need to keep in mind that grep will return any line containing the search pattern in any position. If you get unintended results, you will need to narrow down the search pattern.

Understanding the way grep works is an essential trait of any sysadmin, as it is ubiquitous in the Unix world.

PCS
Jacques Carriere
Regular Advisor

Re: #ps -ef | grep pmon

Good answers. thanks Jacques