[kwlug-disc] tracking down a rampant script

Khalid Baheyeldin kb at 2bits.com
Sat Jan 23 16:37:46 EST 2010

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.

Or even doing it programatically (if you have the permission).


For shell scripts, you can do that like so:

yourprogram -options &
sleep 300
kill $CMD_PID

This will prevent "yourprogram" from running more than 5 minutes per

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);


void shutdown() {

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

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.
Drupal optimization, development, customization and consulting.
Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
Simplicity is the ultimate sophistication. --   Leonardo da Vinci
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20100123/d6d3a15a/attachment.html>

More information about the kwlug-disc mailing list