geohar has asked for the wisdom of the Perl Monks concerning the following question:
I'm running OSX, so some explanation of how applications show up in ps listings may be required. Using ps -axwwo command= I'll get a list of processes including those without controlling terminals, and doesn't width-limit the result and only prints the command path + arguments.
As well as the applications which are running, there's also going to be a fair few other processes. I don't want those in the list.
The rules for how an application looks in the ps listing:
1. All applications have XXX.app/Contents/ in their path, the actual executable being at something like somepath/XXX.app/Contents/MacOS/XXX Or perhaps somepath/XXX.app/Contents/MacOSClassic/XXX. Anyhow, all applications have XXX.app/Contents/ in their path.
2. Applications may infact be nested (helper apps etc). So may appear as somepath/XXX.app/Contents/Resources/Helper.app/Contents/MacOS/Helper which kinda confuses things somewhat, as the running app is actually Helper, not XXX.
3. In the ps listing you have often a postfixed "-psn=101010" indicating the psn of the application.
4. Incidentally application names may contain spaces ;(
I want a listing consisting of the running applications, only. In the form
A.app B.app C.app
etc. even when C.app may be inside D.app's bundle folder.
Yeah, this is very esoteric.
So currently, I have the following line which I execute in tcsh.
/bin/ps -axwwo command= | grep '\.ap\{2\}/Contents' | perl -p -e 's|^/(([^/]+)+/)+(.+\.app)/.*$|$3|'
Can anyone do better? I'm looking for a one-liner. I'd love to fold the grep into the perl, but it complicates processes finding themselves, and I couldn't see how to do it as a perl filter...
Note that the use of the grep and it's bizarre construction means it doesn't match itself or the perl filter.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The simplest (perl) filter for the job
by ccn (Vicar) on Oct 15, 2004 at 09:30 UTC | |
by geohar (Acolyte) on Oct 15, 2004 at 10:03 UTC | |
by geohar (Acolyte) on Oct 15, 2004 at 11:07 UTC | |
by geohar (Acolyte) on Oct 15, 2004 at 11:13 UTC | |
|
Re: The simplest (perl) filter for the job
by Roger (Parson) on Oct 15, 2004 at 12:09 UTC |