Code Comments
Programming Forum and web based access to our favorite programming groups.
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.
Post Follow-up to this messageJ 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
Post Follow-up to this messageJ 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
Post Follow-up to this messageIn 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 mcse.ms - Unlimited-Uncensored-Secure Usenet News==-
---
http://www.mcse.ms The #1 Newsgroup Service in the World! >100,000 New
sgroups
---= 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 =----
-
Post Follow-up to this messageici 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
Post Follow-up to this messageOn 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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.