[X-Unix] Command to find if a certain app is running?
Juan Manuel Palacios
jmpalaciosp at eml.cc
Fri Mar 27 10:20:50 PDT 2009
On Mar 27, 2009, at 9:54 AM, TjL wrote:
> On Fri, Mar 27, 2009 at 2:58 AM, Christoph Hammann
> <chammann at mac.com> wrote:
>> The first command you're looking for is ps aux | grep processname .
>> The
>> second is apropos .
>>
>
> It is often a good idea to throw out 'grep' in the responses for grep
> (and, the 'w' as someone else mentioned)
>
> ps auxwwwww | grep iTunes | grep -v grep
There's an alternative to this filtering technique (note that purpose
of the backlash in front of my ps command is only to temporarily turn
off the shell alias I have setup for it, as outlined in my previous
reply to this thread):
$[jmpp @jmpp: Documents](38/0 0,0) -> \ps -A | grep -i itunes
291 ?? 0:01.03 /Applications/iTunes.app/Contents/Resources/
iTunesHelper.app/Contents/MacOS/iTunesHelper -psn_0_86037
300 ?? 3:04.85 /Library/PreferencePanes/
SizzlingKeys.prefPane/Contents/Resources/SizzlingKeys4iTunes.app/
Contents/MacOS/SizzlingKeys4iTunes -psn_0_110619
302 ?? 77:54.21 /Applications/iTunes.app/Contents/MacOS/
iTunes -psn_0_114716
21769 ttys005 0:00.00 grep -i itunes
Now we pipe to a second grep to filter the grep result itself:
$[jmpp @jmpp: Documents](39/0 0,0) -> \ps -A | grep -i itunes | grep -
v grep
291 ?? 0:01.03 /Applications/iTunes.app/Contents/Resources/
iTunesHelper.app/Contents/MacOS/iTunesHelper -psn_0_86037
300 ?? 3:04.85 /Library/PreferencePanes/
SizzlingKeys.prefPane/Contents/Resources/SizzlingKeys4iTunes.app/
Contents/MacOS/SizzlingKeys4iTunes -psn_0_110619
302 ?? 77:54.27 /Applications/iTunes.app/Contents/MacOS/
iTunes -psn_0_114716
But there is a pretty cool way to do it in just a single pipe-to-grep
operation:
$[jmpp @jmpp: Documents](40/0 0 0,0) -> \ps -A | grep -i [i]tunes
291 ?? 0:01.03 /Applications/iTunes.app/Contents/Resources/
iTunesHelper.app/Contents/MacOS/iTunesHelper -psn_0_86037
300 ?? 3:04.85 /Library/PreferencePanes/
SizzlingKeys.prefPane/Contents/Resources/SizzlingKeys4iTunes.app/
Contents/MacOS/SizzlingKeys4iTunes -psn_0_110619
302 ?? 77:54.33 /Applications/iTunes.app/Contents/MacOS/
iTunes -psn_0_114716
I can't really remember the regular expression fu that takes place
with the brackets surrounding the first letter of the search pattern
(I do remember that it's more complicated that I'd originally thought
when I first read on it), but in any case it does take care of
filtering the grep command from the ps output since it doesn't match
the pattern. The -i in the now-one-and-only grep filter only buys us
case-insensitive matching, so as to be able to type itunes rather than
iTunes.
HTH!
-jmpp
More information about the X-Unix
mailing list