Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Perl interface to Unix ps?



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.


Report this thread to moderator Post Follow-up to this message
Old Post
J Krugman
12-23-04 09:07 PM


Re: Perl interface to Unix ps?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Douglas Hunter
12-23-04 09:07 PM


Re: Perl interface to Unix ps?
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

Report this thread to moderator Post Follow-up to this message
Old Post
chris-usenet@roaima.co.uk
12-23-04 09:07 PM


Re: Perl interface to Unix ps?
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 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 =----
-

Report this thread to moderator Post Follow-up to this message
Old Post
Jim Gibson
12-23-04 09:07 PM


Re: Perl interface to Unix ps?
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



Report this thread to moderator Post Follow-up to this message
Old Post
DominiX
12-24-04 09:15 AM


Re: Perl interface to Unix ps?
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.


Report this thread to moderator Post Follow-up to this message
Old Post
Mladen Gogala
12-27-04 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:13 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.