On 2005–10–13, at 12:40, David Cantrell wrote:

On Thu, Oct 13, 2005 at 08:51:22AM +0200, Dominic Dunlop wrote:

A late arrival which hasn't been mentioned so far:
$ killall -0 Illustrator 2>/dev/null && echo "Illustrator is running"


killall is a Really Bad Idea.  While it does indeed do what you intend
on OS X, on other commercial Unices like Solaris it really does kill
all. That is, it sends your chosen signal to all processes. Not good.
So don't get in to the habit of using it.

Aw, cut me some slack. This was specifically a Mac OS X query (Illustrator not being available on Solaris); the Solaris command only does its dangerous stuff for root (according to the man page -- I don't have access to a Sun box); and Sun puts it in a place that shouldn't be on a normal user's PATH. Plus killall, BSD-style, is a neat command. Works on Linux too. But anyway. Here's Yet Another Way To Do It:

#!/usr/bin/perl -wl

use Proc::ProcessTable;
my $t = new Proc::ProcessTable;
for (@{$t->table}) {
  if ($_->cmndline =~  m%/Mail.app/%) { # *** Your app name here ***
    print $_->pid;
    last;
  }
}

Proc::ProcessTable is available from CPAN, and builds and runs without problem on Mac OS X. It also works in a lot of other environments (including Windows) (and Solaris).

Sadly, this approach no good for use from an optionally installed package, as you can't rely on the module being present. (Unless you were to include it as part of the bundle and tell perl how to find it, which would probably be more trouble than it's worth.)
--
Dominic Dunlop

Reply via email to