- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ps -ef appname|grep -v grep : How to avoid g...
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
10-07-2008 10:55 AM
10-07-2008 10:55 AM
Anyone remember what that construct is?
;^)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2008 10:58 AM
10-07-2008 10:58 AM
Solution# UNIX95= ps -C cron -o pid
...for example to find the 'cron' daemon pid.
To suppress the header, use:
# UNIX95= ps -C cron -o pid=
Note the whitespace after UNIX95= . This keeps the setting only for the duration of the command line --- something that you truly want to do.
Regards!
...JRF...
- Tags:
- UNIX95
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2008 11:00 AM
10-07-2008 11:00 AM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
Am just after a bulet proof way of finding out if process "appname" is running with out the "grep -v grep" as it is thought to waste .00000000000000000018 CPU cycle :^))
It's actually a trivia amongst my team.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2008 11:01 AM
10-07-2008 11:01 AM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
Make one of the characters a 'range'
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2008 11:26 AM
10-07-2008 11:26 AM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
> I am not after the PID man..
Am just after a bulet proof way of finding out if process "appname" is running with out the "grep -v grep" as it is thought to waste .00000000000000000018 CPU cycle :^))
That was not the point. The point is that the '-C' switch allows the argument (name) following it to be found based on an exact match to the process basename.
This avoids ambiguous false positive matches and avoids the need to 'grep -v grep'. Of course you could use 'awk' or Perl to pattern match a process basename too.
The '-o' argument(s) allows you to choose what to return --- a pid; the arguments passed (if any) to the process(es); the elapsed time, etc.
Thus, given a process name, the method I showed *is* a very bullet proof way of saying "yes" or "no" to the question of "is a process running". It's not a question of useless processes, forks and CPU cycles.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2008 12:27 PM
10-07-2008 12:27 PM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
actually, i think the option you want is on the ps command
UNIX95= ps -fC prngd or
UNIX95= ps -C prngd
will find those processes running the executable with the file base name indicated shown below
UNIX95= ps -C prngd
PID TTY TIME CMD
963 ? 37:20 prngd
the -f will show the full path of the command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2008 01:34 PM
10-07-2008 01:34 PM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
The answer is to put one of the letters of the appname in square brackets:
ps -ef | grep _[p]mon
for example. It's convoluted typing, so I normally end up doing the grep -v grep myself.
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2008 04:31 PM
10-07-2008 04:31 PM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
NEVER use grep with ps.
All the options you need for searching for processes are found in the ps man page. NEVER grep for a PID, use ps -p. Never grep for an owner, use ps -u. Never grep for a process name, use UNIX95=1 ps -C. Note that the -C is not just the basename of the process, it is the actual name found in the process table. It turns out that (hacker code sometimes) can change the name of the process after it starts. The -C option looks in the process table and not the command line string.
grep is not field-sensitive so it looks at every character and it doesn't care about things you don't want matched. grep 123 will also match 11233 and parm131234. Just compare the output of these two commands on your system:
ps -ef | grep sh
UNIX95=1 ps -fC sh
Not only will exactly "sh" be found (rather than unhashdaemon, ksh, bash, etc), but the login shells -sh will also be found. The -w option in grep will find "sh" as a word but treat special chars as a delimiter, still leading to mistakes, especially in command line parameters and strings.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2008 08:40 PM
10-07-2008 08:40 PM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
It is probably much easier to show the following, than to explain about whitespace:
UNIX95=1 ps ...
(Of course you need to say, "No semicolons".)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 05:13 AM
10-08-2008 05:13 AM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
> Dennis: It is probably much easier to show the following, than to explain about whitespace: UNIX95=1 ps ...
The problem I see with this is that it suggests to the reader that the opposite case (to turn off) might be "UNIX95=0 ps ...".
Unfortunately this is a fallacious assumption. The action 'UNIX95= ' or 'UNIX95=0' or 'UNIX95=1' equally result in an defined value which toggles the XPG behavior. Simply compare:
UNIX95= ps -C sh
UNIX95=0 ps -C sh
UNIX95=1 ps -c sh
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 06:05 PM
10-08-2008 06:05 PM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
James is quite right. This variable is part of the XPG4 specifications which defines the existence of the variable as true. So once UNIX95=anything_including_null, the defined behavior is asserted.
Big precaution: Don't export or set UNIX95 in your environments. It can change the behavior of a number of processes and libraries. That's why it is shown assigned on the same line as the process (ie, ps). The definition stays only with the process and disappears when the process terminates. This assignment on the same line as a process is a standard POSIX construct (read: ksh, bash, HP POSIX shell).
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 08:15 PM
10-08-2008 08:15 PM
Re: ps -ef appname|grep -v grep : How to avoid grep -v grep?"
Ok, then use: ;-)
UNIX95=EXTENDED_PS_FEATURES ps ...
- Tags:
- EXTENDED_PS