Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl equivalent for Unix ps.

Reply
Thread Tools

Perl equivalent for Unix ps.

 
 
Prab_kar@hotmail.com
Guest
Posts: n/a
 
      01-30-2005
Hi all,
Is there any Perl function which works like the Unix ps command?
I've looked through the manuals for Perl functions and couldnt find
anything similar in nature.

I'm rewriting a Bourne shell script in Perl and the sh script uses the
ps from a lot of different places, /usr/bin/ps sometimes, /usr/ucb/ps
other times. I wanted to rewrite in Perl to get over that, and in all
the examples I see, the Perl scripts use /usr/bin/ps or /usr/ucb/ps in
backticks or from system("<PATH>/ps").

Is there anyway I can use Perl's internal functions to identify/monitor
the process and stop/kill them?
I realize there's Proc:rocessTable .pm for this, but I want my
distribution to include just the Perl script and have it do it all.
I'm working on Solaris, Perl 5.6.

Thanks for your time,
Prabh

 
Reply With Quote
 
 
 
 
Jim Keenan
Guest
Posts: n/a
 
      01-31-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi all,
> Is there any Perl function which works like the Unix ps command?
> I've looked through the manuals for Perl functions and couldnt find
> anything similar in nature.
>


See the discussion here (which, unfortunately, rains on your parade):

http://search.cpan.org/~nwclark/perl...ell.pm#Caveats

jimk




 
Reply With Quote
 
 
 
 
Gregory Toomey
Guest
Posts: n/a
 
      01-31-2005
(E-Mail Removed) wrote:

> Hi all,
> Is there any Perl function which works like the Unix ps command?
> I've looked through the manuals for Perl functions and couldnt find
> anything similar in nature.
>
> I'm rewriting a Bourne shell script in Perl and the sh script uses the
> ps from a lot of different places, /usr/bin/ps sometimes, /usr/ucb/ps
> other times. I wanted to rewrite in Perl to get over that, and in all
> the examples I see, the Perl scripts use /usr/bin/ps or /usr/ucb/ps in
> backticks or from system("<PATH>/ps").
>
> Is there anyway I can use Perl's internal functions to identify/monitor
> the process and stop/kill them?
> I realize there's Proc:rocessTable .pm for this, but I want my
> distribution to include just the Perl script and have it do it all.
> I'm working on Solaris, Perl 5.6.
>
> Thanks for your time,
> Prabh


If you dont want to use ProcessTable.pm, then in linux I use the output from
ps:

sub killem {
my($pid,$tname,$etime,$cmd,$emin,$ehour,$backgroun d);

for (split '\n', qx(ps -u $> -o pid,tname,etime,cmd --no-headers)) {
($pid, $tname, $etime,$cmd) = unpack "a5 x a11 x a8 x a200"
$_;
#print "$_\n";
$etime =~ /((\d*)?(\d*)\d*)$/;
$ehour = $2;
$emin = $3;
$background=/\?/;
next if $pid==$$;

if ($ehour>12 || ((!/sshd/)&&$background&&($ehour>=1|
$emin>10))) {
log('Killing '.$_);
kill 9,$pid;
}
}
}

gtoomey
 
Reply With Quote
 
Prab_kar@hotmail.com
Guest
Posts: n/a
 
      01-31-2005
Thanks for your response, Jim and Greg.

My problem is I want to use pure Perl to do this.
I dont want to get into the whole platform check routine of,
If Linux
Use ps from /bin/ps
Else if Solaris
Use ps from /usr/bin/ps or /usr/ucb/ps

I wanted to see if pure Perl can give me the same info that the running
ps from backticks or system("ps") would give.
Unfortunately, that doesnt seem to be the case.
Thanks for your time,
Prabh

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      01-31-2005
Michael Vilain wrote:
> In article <(E-Mail Removed) .com>,
> (E-Mail Removed) wrote:
>>
>>I wanted to see if pure Perl can give me the same info that the running
>>ps from backticks or system("ps") would give.
>>Unfortunately, that doesnt seem to be the case.

>
> what's wrong with opening a filehandle (e.g.
>
> open (PS,"ps -ef") && die "can't open ps: $!\n";


Did you try that? When you try to open the file 'ps -ef' what happens?


John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl equivalent of unix time command Melroy Perl Misc 13 09-09-2008 02:28 PM
Perl equivalent to unix script Mike Perl Misc 11 11-03-2006 02:58 PM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-22-2004 10:59 PM
#!perl instead of #!/usr/bin/perl on a Unix/Apache webserver joe Perl Misc 8 11-14-2003 10:58 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments