[X-Unix] Command to find if a certain app is running?

Juan Manuel Palacios jmpalaciosp at eml.cc
Fri Mar 27 10:09:48 PDT 2009


On Mar 27, 2009, at 2:28 AM, Christoph Hammann wrote:

> Hi,
>
> The first command you're looking for is ps aux | grep processname .


	Please note that ps in Leopard changed. I can't for the life of me  
remember at the moment if Tiger's ps (and that of previous Mac OS X  
releases) followed the gnu standard (POSIX on some aspects, plus many  
gnu'isms) or BSD's or SYSV's or who-knows-what-else, but if I'm not  
mistaken Leopard' ps is UNIX03 compliant.

	Now what does all that mean? That the flags changed considerably from  
the I-was-already-too-used-to "aux" combo. Leopard's equivalent would  
be something like "ps -Axv":

A: display info on all processes, including other users' and those  
without a controlling terminal (e.g. daemons & GUI apps);
x: ensure processes without controlling terminals are displayed, as  
some other ps options might filter their output;
v: display specific process metadata, consult "man ps" for details.

	To that mix you can add options like -j, for extra process metadata  
(like the process' parent's Id, aka PPID), -h to repeat the column  
headers as often as necessary, since the output will likely be pretty  
long, and as many -w's as needed for desired row length. All in all:

$[jmpp @jmpp: ~](23/1 0,0) -> alias ps
alias ps='/bin/ps -jAxvwwh'

	Lastly, don't forget to include the dash in front of the ps options,  
since its presence does change its behavior on some systems (e.g.,  
Linux's ps sometimes even flat-out bailing due to incorrect command  
syntax). I don't think it's the case for Leopard, or I least I haven't  
been able to attest to it, but all in all consistency is a pretty good  
thing.


> The second is apropos .
>

	That's equivalent to "man -k your-search-term-here". I find that  
handy 'cause if I did find the correct command name, I can easily go  
back to delete the -k part and hit enter right away to get the manual  
page.

> HTH!
>


	Regards,...


-jmpp


>
> Am 27.03.2009 um 06:42 schrieb Jerry Krinock <jerry at ieee.org>:
>
>> Does anyone know if there is a command to find if a certain app is  
>> running?
>>
>> I know one way to do this would be via osascript/AppleScript,
>>
>>  tell application "System Events" set allApps to every application  
>> process
>>
>> and then parse the list returned but I'd like to avoid the  
>> backslash-escape hell of osascript if possible.
>>
>> Is there a command-line interface to System Events?
>>
>> Thanks,
>>
>> Jerry Krinock
>>
>> P.S.  More generally, is there a way to search for "a command that  
>> will do XYZ" on OS X?  Example: Earlier today, I wanted to read/ 
>> write user preferences but had difficulty remembering the command  
>> name 'defaults'.
>>
>>
>> _______________________________________________
>> X-Unix mailing list
>> X-Unix at listserver.themacintoshguy.com
>> http://listserver.themacintoshguy.com/mailman/listinfo/x-unix
> _______________________________________________
> X-Unix mailing list
> X-Unix at listserver.themacintoshguy.com
> http://listserver.themacintoshguy.com/mailman/listinfo/x-unix



More information about the X-Unix mailing list