Using perl to watch other programs
Using perl to watch other programs
am 07.11.2007 14:59:55 von 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)?
Bill H
Re: Using perl to watch other programs
am 07.11.2007 15:01:20 von Bill H
On Nov 7, 8:59 am, Bill H 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
Re: Using perl to watch other programs
am 07.11.2007 15:10:38 von Josef Moellers
Bill H wrote:
> On Nov 7, 8:59 am, Bill H wrote:
>=20
>>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
>=20
>=20
> FYI this is on a linux server
You could have your Perl program scan the output of "ps aux" and kill=20
all processes that have a runtime of more than 1 minute.
However, as Linux boxen often live for lengthy times, there might be=20
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 =3D 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} =3D split(/\s+/, $_, scalar @fn);
next unless $info{TIME} =3D~ /^0:/;
kill 9, $info{PID} if $info{COMMAND} =3D~ /client/;
}
close $psaux;
}
--=20
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
Re: Using perl to watch other programs
am 07.11.2007 16:14:44 von Ben Morrow
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::ProcessTable to see what's going on with
the other processes on the machine.
Ben
Re: Using perl to watch other programs
am 07.11.2007 16:39:08 von Ted Zlatanov
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
Re: Using perl to watch other programs
am 07.11.2007 19:33:26 von Bill H
On Nov 7, 10:14 am, Ben Morrow wrote:
> 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::ProcessTable to see what's going on with
> the other processes on the machine.
>
> Ben
What is setrlimit?
Bill H
Re: Using perl to watch other programs
am 08.11.2007 03:36:13 von Ben Morrow
Quoth Bill H :
> On Nov 7, 10:14 am, Ben Morrow 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