Perl interface to Unix ps?

Discussion in 'Perl Misc' started by J Krugman, Dec 23, 2004.

  1. J Krugman

    J Krugman Guest

    I'm writing a Perl script that is supposed to find the PIDs of all
    the running versions of a program and send them a SIGUSR1. As this
    description suggests, the script is meant for a Unix platform, but
    it could be Linux, BSD, Solaris, etc.

    The only way I can think of to get the PIDs for all the desired
    processes is to scan the output of a suitable 'system "ps -blah"'
    call, but there are many versions of ps around, each with its own
    syntax and output format. Does anyone know of a Perl interface
    for ps? (I searched perldoc -q ps, man POSIX, and CPAN for ps but
    didn't find anything; I'm hoping that what I'm looking for exists
    in some less obvious place.)

    TIA,

    jill


    --
    To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
    J Krugman, Dec 23, 2004
    #1
    1. Advertising

  2. J Krugman

    Guest

    J Krugman <> wrote:
    > I'm writing a Perl script that is supposed to find the PIDs of all
    > the running versions of a program and send them a SIGUSR1. As this
    > description suggests, the script is meant for a Unix platform, but
    > it could be Linux, BSD, Solaris, etc.


    As the risk of upsetting others in clpm, since it's for a *IX platform,
    why write this in perl? This will send SIGUSR1 to any process called
    "program":

    kill -USR1 `ps -e | awk '$NF == "program" {print $1}'`

    YMMV depending on which variant of ps you have (i.e. whether you're on
    a SysV or BSD derived platform), but then the perl alternatives seem to
    struggle with platform dependence, too, as they appear to depend on the
    existence of /proc.

    Chris
    , Dec 23, 2004
    #2
    1. Advertising

  3. J Krugman

    Keith Keller Guest

    [OT] kill/killall (was: Perl interface to Unix ps?)

    On 2004-12-23, Jim Gibson <> wrote:
    >
    > There is also the Unix killall utility:
    >
    > killall -USR1 programname


    Apparently killall does not behave the same way on every OS: there are
    some notes on Solaris killall, for example, that suggest it's a bit more
    extreme (it kills all processes, thus killall).

    --keith

    --
    -francisco.ca.us
    (try just my userid to email me)
    AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
    Keith Keller, Dec 23, 2004
    #3
  4. J Krugman

    DominiX Guest

    ici même:J Krugman <> a écrit
    > I'm writing a Perl script that is supposed to find the PIDs of all
    > the running versions of a program and send them a SIGUSR1. As this
    > description suggests, the script is meant for a Unix platform, but
    > it could be Linux, BSD, Solaris, etc.
    >

    ....
    >
    > TIA,
    >
    > jill


    for that purpose I use Proc::processTable;

    HTH

    -- dominix
    DominiX, Dec 24, 2004
    #4
  5. On Thu, 23 Dec 2004 14:24:40 +0000, J Krugman wrote:

    > I'm writing a Perl script that is supposed to find the PIDs of all
    > the running versions of a program and send them a SIGUSR1. As this
    > description suggests, the script is meant for a Unix platform, but
    > it could be Linux, BSD, Solaris, etc.


    #!/usr/bin/perl -w
    use strict;
    my @proclist=();

    open BS,"ps -ef|" or die "Cannot open BS:$!\n";
    while (<BS>) {
    my @fields=split /\s+/;
    push @proclist,$fields[1];
    }
    kill 10, @proclist
    $

    --
    Artificial Intelligence is no match for natural stupidity.
    Mladen Gogala, Dec 27, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,765
  2. Replies:
    12
    Views:
    1,612
    Dave Thompson
    Jan 10, 2005
  3. Replies:
    18
    Views:
    607
    Dave Thompson
    Jan 10, 2005
  4. joe
    Replies:
    8
    Views:
    183
    Matthias Weckman
    Nov 14, 2003
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    264
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page