For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > December 2004 > Perl interface to Unix ps?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Perl interface to Unix ps?
J Krugman

2004-12-23, 4:07 pm





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.

Douglas Hunter

2004-12-23, 4:07 pm

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.
>
> 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.)


I've had success with Proc::ProcessTable
(http://search.cpan.org/~durist/Proc-ProcessTable-0.39/). By its
reviews it seems that others have as well. If the Unix that you run
isn't supported (darwin, nonstop-ux windows, linux, solaris, aix,
hpux, freebsd, irix, dec_osf, bsdi, netbsd, unixware 7.x and
SunOS are the currently supported platforms) there is a PORTING document
that you might find useful.

One of the reviews says, "Never need to parse 'ps' commands again".
Joy! ;-)

-- Douglas
chris-usenet@roaima.co.uk

2004-12-23, 4:07 pm

J Krugman <jkrugman345@yahbitoo.com> 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
Jim Gibson

2004-12-23, 4:07 pm

In article <nrar92-4qb.ln1@moldev.cmagroup.co.uk>,
<chris-usenet@roaima.co.uk> wrote:

> J Krugman <jkrugman345@yahbitoo.com> wrote:
>
> 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.


There is also the Unix killall utility:

killall -USR1 programname


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
DominiX

2004-12-24, 4:15 am

ici même:J Krugman <jkrugman345@yahbitoo.com> 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


Mladen Gogala

2004-12-27, 3:55 am

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.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com