[kwlug-disc] tracking down a rampant script

Eric Gerlach eric+kwlug at gerlach.ca
Sun Jan 24 19:40:09 EST 2010


Assuming this is on Linux, you should be able to set the ulimit as well.
Not sure how that would work with a CGI script, though.

Cheers,

Eric

On Sat, Jan 23, 2010 at 04:37:46PM -0500, Khalid Baheyeldin wrote:
> You say "compiled" so I am not sure what language the script is in.
> 
> But there is a way to prevent a script from running more than a certain
> number of seconds. For example PHP provides a parameter for exactly
> that, and you can change it depending on your needs.
> 
> http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time
> Or even doing it programatically (if you have the permission).
> 
> http://php.net/manual/en/function.set-time-limit.php
> 
> For shell scripts, you can do that like so:
> 
> #!/bin/sh
> yourprogram -options &
> CMD_PID=$!
> sleep 300
> kill $CMD_PID
> 
> This will prevent "yourprogram" from running more than 5 minutes per
> invocation.
> 
> For C programs, you can use signal(SIGALRM, ...) and alarm(300) to make the
> program terminate after a while.
> 
> int main(void) {
>   signal(SIGALRM, shutdown);
> 
>   alarm(300);
> }
> 
> void shutdown() {
>   exit();
> }
> 
> But you say it is compiled and it is called from web pages.
> 
> Please provide more specifics and I/we will try to see what more can be
> done.
> 
> On Sat, Jan 23, 2010 at 4:13 PM, Insurance Squared Inc. <
> gcooke at insurancesquared.com> wrote:
> 
> > I've got a compiled script running on my webserver that runs alot, called
> > by various webpages.
> >
> > Once in a while it seems like the script doesn't stop running; it keeps on
> > running and chewing up huge amounts of cpu.  So after a couple of days, I
> > end up with 2 or 3 instances of that script running on the server
> > continually.  running 'top' will show 0% idle cpu, with all the cpu being
> > consumed by that script (with an owner of apache).  Kill the pids,
> > everything performs nice again...for a little while.
> >
> > Meantime, thousands of other executions of the script perform properly -
> > they execute for a brief second, spit out their numbers, then die
> > gracefully.
> >
> > How would one diagnose or stop this sporadic rogue behavior?
> >
> >
> >
> > _______________________________________________
> > kwlug-disc_kwlug.org mailing list
> > kwlug-disc_kwlug.org at kwlug.org
> > http://astoria.ccjclearline.com/mailman/listinfo/kwlug-disc_kwlug.org
> >
> 
> 
> 
> -- 
> Khalid M. Baheyeldin
> 2bits.com, Inc.
> http://2bits.com
> Drupal optimization, development, customization and consulting.
> Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
> Simplicity is the ultimate sophistication. --   Leonardo da Vinci

> _______________________________________________
> kwlug-disc_kwlug.org mailing list
> kwlug-disc_kwlug.org at kwlug.org
> http://astoria.ccjclearline.com/mailman/listinfo/kwlug-disc_kwlug.org





More information about the kwlug-disc mailing list