http://www.perlmonks.org?node_id=314889

glwtta has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Ok, here is my problem: Under mod_perl (running Apache::Registry), I have a script that generates and image and sends it as the output. The image is generated by a third-party module (more specifcially, GraphViz), and can sometimes take a very long time to run (without any really good way to predict when).

Now from the application point of view it would be perfectly fine to just hit Stop on the browser if the image is taking too long and go on about your business (in other words, it's not all that essential for it to complete), of course if a user does that, then the neato process spawned by graphviz will just sit there, eating up cycles (often indefinitely). After a while I'll get enough of the little buggers that all the CPUs are continously busy.

So, what to do? I understand that I can use Apache->request->connection->aborted to check if the user has terminated the session, but that only helps if I am in some sort of loop where I can do the actual check. As it is, I am sitting waiting for GraphViz to do it's thing. I have a vague idea about forking off the process and then having the parent sit in a loop over the connection->aborted check and kill the child (must computer terminology be so morbid?) if it detects a broken connection. But I just don't know enough about IPC to know exactly what to do here.

Any suggestions? Thanks in advance.