Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > How do you grep for processes in OS X?

How do you grep for processes in OS X?
Thread Tools
Mac Elite
Join Date: Feb 2002
Location: Hilton Head, SC
Status: Offline
Reply With Quote
Mar 30, 2005, 10:10 PM
 
When I try the normal way I get an error:

Thaidogs-G4:/usr/sbin tylerm$ ps -ef | grep mysql

ps: illegal option -- f
usage: ps [-aChjlmMrSTuvwx] [-O|o fmt] [-p pid] [-t tty] [-U user]
[-N system] [-W swap]
ps [-L]
     
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Mar 30, 2005, 10:23 PM
 
I usually use ps -acx

-a is "Display information about other users' processes as well as your own."

-c is "Change the ``command'' column output to just contain the executable name, rather than the full command line." If you don't do this or -ww, the name of the executable may be hidden because the path to it is too long.

-x is "Display information about processes without controlling terminals."
     
Mac Elite
Join Date: Feb 2002
Location: Hilton Head, SC
Status: Offline
Reply With Quote
Mar 30, 2005, 10:37 PM
 
Originally posted by wataru:
I usually use ps -acx

-a is "Display information about other users' processes as well as your own."

-c is "Change the ``command'' column output to just contain the executable name, rather than the full command line." If you don't do this or -ww, the name of the executable may be hidden because the path to it is too long.

-x is "Display information about processes without controlling terminals."
So what would be the full command?

ps -acx | grep mysql ?
     
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Mar 30, 2005, 10:56 PM
 
Yes. The problem was that ps didn't like the -f tag for whatever reason. The rest is correct.
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Mar 30, 2005, 11:03 PM
 
ps -ef

is the common usage in the System V based unix world.

ps -ax

is the common usage in the BSD based unix world.

With the divergence of unix-y operating systems, some commands which are similar on the different versions do actually use different arguments for different things.

In some cases you may also find the the GNU versions of some commands (usually used in Linux distributions) may be different again, but in most cases they'd be based on either System V or BSD versions.
     
Mac Elite
Join Date: Feb 2002
Location: Hilton Head, SC
Status: Offline
Reply With Quote
Mar 31, 2005, 12:23 AM
 
I'm used to working on Solaris, AIX and Linux.... all of them that I have used use the ps -ef metaphor.... thanks for the explanation
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Mar 31, 2005, 05:25 AM
 
I usually use

ps -ax | grep foo

I was trying to refine this the other day - so exclude the 'grep foo' process from the list - but my Regex skills failed massively - and I couldn't work out how to exclude processes that contain "grep"

Anyone know how to do this?
     
Dedicated MacNNer
Join Date: May 2004
Status: Offline
Reply With Quote
Mar 31, 2005, 10:16 AM
 
Yes, the BSD heritage of OSX is showing here! I use ps -ef on SYSV, and ps aux on BSD.
╭1.5GHz G4 15" PB, 2.0GB RAM, 128MB VRAM, 100GB 7200rpm HD, AEBS, BT kbd
╰2.0GHz T2500 20" iMac, 1.5GB RAM, 128MB VRAM, 250GB 7200rpm HD

http://www.DogLikeNature.com/
     
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
Mar 31, 2005, 10:34 AM
 
Originally posted by Diggory Laycock:
I usually use

ps -ax | grep foo

I was trying to refine this the other day - so exclude the 'grep foo' process from the list - but my Regex skills failed massively - and I couldn't work out how to exclude processes that contain "grep"

Anyone know how to do this?
ps -ax | grep foo | grep -v grep

The -v flag returns all lines that don't match the search string.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Mar 31, 2005, 10:39 AM
 
Great - Thanks!
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Mar 31, 2005, 11:48 AM
 
Use either acux or auwwx otherwise you could miss it depending on the width of your terminal window
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 05:01 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2