- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grep artifacts
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 01:01 AM
01-27-2005 01:01 AM
oracle 962572 1 0 Jan 11 - 2:13 ora_pmon_ATCQ2
but sometimes I get pmon, and grep also catches "itself" i.e. same command as above returns:
oracle 962572 1 0 Jan 11 - 2:13 ora_pmon_ATCQ2
oracle 1495276 2539608 0 08:55:20 pts/1 0:00 grep pmon
However, if I type "ps -ef | grep pmon | grep ATCQ2" it always returns just the proc of interest, and grep never detects itself as above.
My question is, why should this be the case ? I use ps -ef often for program control steps such as running parallel commands in their own shell, and the feature of grep was something found by trial and error, but I wondered if there is a reason for it.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 01:05 AM
01-27-2005 01:05 AM
Re: grep artifacts
It would be safer to do "ps -e | grep pmon" instead of "ps -ef | grep pmon". This will eliminate the grep.
You could also do "ps -ef | grep pmon | grep -v grep", however, this adds yet another unnecessary system call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 01:06 AM
01-27-2005 01:06 AM
Re: grep artifacts
If you are doing this within a script the way to solve it is to add an extra 'grep -v grep' to your command. That way the grep process itself will be ignored.
So your command would be:
ps -ef | grep process | grep -v grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 01:08 AM
01-27-2005 01:08 AM
Re: grep artifacts
the correct way is to use the
ps -ef|grep XXX |grep -v grep
regards
Henk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 01:09 AM
01-27-2005 01:09 AM
Re: grep artifacts
The second grep takes it input from the first one: i.e. the two lines described above. As only one of these will have ATCQ2 in it, this is the only line you will see.
You could achieve the same result by:
ps -ef|grep pmon|grep -v grep
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 01:31 AM
01-27-2005 01:31 AM
SolutionTo find an exact command name:
UNIX95= ps -fC mycommand
For example, compare the following:
ps -ef | grep sh
UNIX95= ps -fC sh
You'll notice that the second form ALWAYS matches the process name (sh) while the first method matches sh, ksh, bash, unhashdaemon, sshd and so on. The -C option is disabled by default but turned on whenever UNIX95 is defined. You can define it with just UNIX95= or set it to any value such as UNIX95=1. The ps program doesn't care. DO NOT export UNIX95 on a separate line!! This is a pervasive variable that when it is set, will change the behavior of several libraries (and thus applications) as well as certain programs. In the case of ps, just include it on the same line (as shown above) and it disappears once the command is finished.
There are dozens of options to select proceses, and two additional UNIX95 values: -H and -o. Try this:
UNIX95= ps -eH
which shows all the parent/child relationships. Add -f to verify the PID/PPID relationships:
UNIX95= ps -efH
And because -f has extra items, you can use -o to customize your own ps output:
UNIX95= ps -eH -o pid,ppid,ruser,args
You can even customize the headings:
UNIX95= ps -eH -o pid=ProcNumber -o ppid="MY parent" -o ruser="Real User" -o args="Command Line"
The -o option is very sueful for scripting.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 01:50 AM
01-27-2005 01:50 AM
Re: grep artifacts
Gilbert, give that man 11 points!
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 02:47 AM
01-27-2005 02:47 AM
Re: grep artifacts
I tried this on my UNIX box and here is what I got:
# UNIX95= ps -fC sh
ps: Not a recognized flag: C
Usage: ps [-ANaedfklm] [-n namelist] [-F Format] [-o specifier[=header],...]
[-p proclist][-G|-g grouplist] [-t termlist] [-U|-u userlist] [-c classlist]
Usage: ps [aceglnsuvwxU] [t tty] [processnumber]
Similar problems were encountered with the other commands mentioned. Do I have something that is not configured correctly ?
Gil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 02:52 AM
01-27-2005 02:52 AM
Re: grep artifacts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2005 05:03 AM
01-27-2005 05:03 AM
Re: grep artifacts
The error message you're seeing is due to ps not seeing the UNIX95 flag, so the shell you are using is not POSIX standard (ie, not ksh, bash, sh for HP-UX, etc). What do these commands show?
ps
echo $SHELL
And I am assuming you're running HP-UX later than 9.0..(uname -r)
Bill Hassell, sysadmin