Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Using perl to watch other programs

Reply
Thread Tools

Using perl to watch other programs

 
 
Bill H
Guest
Posts: n/a
 
      11-07-2007
Is there a way in perl to watch what is running on a server and close
out applications that appear to be hung?

I am running a perl bulletin board (YaBB) and have been having an
issue where it seems to hang occasionally and not exit, causing server
usage to go up to the point where the server locks up. While I am
trying to determine what is causing this, I would like to do is be
able to close an instance of the program if it is running for more
than 1 minute, can this be done with a perl program (maybe running as
a cron job)?


Bill H

 
Reply With Quote
 
 
 
 
Bill H
Guest
Posts: n/a
 
      11-07-2007
On Nov 7, 8:59 am, Bill H <b...@ts1000.us> wrote:
> Is there a way in perl to watch what is running on a server and close
> out applications that appear to be hung?
>
> I am running a perl bulletin board (YaBB) and have been having an
> issue where it seems to hang occasionally and not exit, causing server
> usage to go up to the point where the server locks up. While I am
> trying to determine what is causing this, I would like to do is be
> able to close an instance of the program if it is running for more
> than 1 minute, can this be done with a perl program (maybe running as
> a cron job)?
>
> Bill H


FYI this is on a linux server

Bill H

 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      11-07-2007
Bill H wrote:
> On Nov 7, 8:59 am, Bill H <b...@ts1000.us> wrote:
>
>>Is there a way in perl to watch what is running on a server and close
>>out applications that appear to be hung?
>>
>>I am running a perl bulletin board (YaBB) and have been having an
>>issue where it seems to hang occasionally and not exit, causing server
>>usage to go up to the point where the server locks up. While I am
>>trying to determine what is causing this, I would like to do is be
>>able to close an instance of the program if it is running for more
>>than 1 minute, can this be done with a perl program (maybe running as
>>a cron job)?
>>
>>Bill H

>
>
> FYI this is on a linux server


You could have your Perl program scan the output of "ps aux" and kill
all processes that have a runtime of more than 1 minute.
However, as Linux boxen often live for lengthy times, there might be
daemons which will fall into this category sooner or later, so you might
need to restrict which commands the target processes must be or must not
be running.

omy @fn = qw (USER PID CPU MEM VSZ RSS TTY STAT START TIME COMMAND);

if (open my $psuax, 'ps aux |') {
while (<$psuax>) {
next if /^USER/;
my %info;
@info{@fn} = split(/\s+/, $_, scalar @fn);
next unless $info{TIME} =~ /^0:/;
kill 9, $info{PID} if $info{COMMAND} =~ /client/;
}
close $psaux;
}

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-07-2007

Quoth Bill H <>:
> Is there a way in perl to watch what is running on a server and close
> out applications that appear to be hung?
>
> I am running a perl bulletin board (YaBB) and have been having an
> issue where it seems to hang occasionally and not exit, causing server
> usage to go up to the point where the server locks up. While I am
> trying to determine what is causing this, I would like to do is be
> able to close an instance of the program if it is running for more
> than 1 minute, can this be done with a perl program (maybe running as
> a cron job)?


The easiest way to do this is with setrlimit: then the OS will kill it
for you.

In general, you can use Proc:rocessTable to see what's going on with
the other processes on the machine.

Ben

 
Reply With Quote
 
Ted Zlatanov
Guest
Posts: n/a
 
      11-07-2007
On Wed, 07 Nov 2007 05:59:55 -0800 Bill H <> wrote:

BH> Is there a way in perl to watch what is running on a server and close
BH> out applications that appear to be hung?

BH> I am running a perl bulletin board (YaBB) and have been having an
BH> issue where it seems to hang occasionally and not exit, causing server
BH> usage to go up to the point where the server locks up. While I am
BH> trying to determine what is causing this, I would like to do is be
BH> able to close an instance of the program if it is running for more
BH> than 1 minute, can this be done with a perl program (maybe running as
BH> a cron job)?

Make your application send out a heartbeat, either by network multicast
or by local IPC methods (the network multicast is generally better as it
also allows for general monitoring). Put the process ID in the
heartbeat packet. Send out every second or whatever.

Your process watcher looks for running processes of interest, listens
for heartbeats, and compares the heartbeat timestamp to the current
time. If the difference is more than N seconds, kill the process.

Ted
 
Reply With Quote
 
Bill H
Guest
Posts: n/a
 
      11-07-2007
On Nov 7, 10:14 am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Bill H <b...@ts1000.us>:
>
> > Is there a way in perl to watch what is running on a server and close
> > out applications that appear to be hung?

>
> > I am running a perl bulletin board (YaBB) and have been having an
> > issue where it seems to hang occasionally and not exit, causing server
> > usage to go up to the point where the server locks up. While I am
> > trying to determine what is causing this, I would like to do is be
> > able to close an instance of the program if it is running for more
> > than 1 minute, can this be done with a perl program (maybe running as
> > a cron job)?

>
> The easiest way to do this is with setrlimit: then the OS will kill it
> for you.
>
> In general, you can use Proc:rocessTable to see what's going on with
> the other processes on the machine.
>
> Ben


What is setrlimit?

Bill H

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-08-2007

Quoth Bill H <>:
> On Nov 7, 10:14 am, Ben Morrow <b...@morrow.me.uk> wrote:
> >
> > The easiest way to do this is with setrlimit: then the OS will kill it
> > for you.

>
> What is setrlimit?


man 2 setrlimit

Your shell probably has a ulimit builtin that calls setrlimit, or you
can call it from Perl with BSD::Resource. You will want to call it in a
wrapper around the program that you're trying to apply the limit to;
something like

#!/bin/sh

ulimit -t 70
exec /path/to/real/binary

Ben

 
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
Re: Swiss Watch International Limited Edition Moon Phase IndicatorMen's Watch A9242.S.S.A1 PinkFloyd43 Digital Photography 1 08-22-2008 01:04 PM
Can't delete certain programs using Add or Remove Programs rbhudson47 Computer Support 3 10-14-2007 12:54 AM
Book: Higher-Order Perl: Transforming Programs with Programs Casey Hawthorne Perl Misc 14 07-14-2005 06:43 PM
Passing variables from Perl to other programs Efialtis Perl Misc 3 05-19-2004 04:05 AM
Can i using j2me program to download and run other j2me programs in emulator? robin Java 0 07-20-2003 12:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57