Kill processes after web page closes

P

Petyr David

I have a PERL-CGI application. I gather input from user, start PERL
script and build a new web page based on input. At the top of the
newly created page is a command button to return the user to the
previous page. If the user clicks the command button and is returned
to the previous page before the page has been completely built, I
find the PERL script is still running. It eventually dies (20 - 30
seconds). I'd like to kill the process as soon as the user returns to
the original page.

How do I determine when that happens?

I'd also like to be able to delete temp files that are deleted when
the PERL script normally completes.

Thanks for your help!
 
S

smallpond

I have a PERL-CGI application. I gather input from user, start PERL
script and build a new web page based on input. At the top of the
newly created page is a command button to return the user to the
previous page. If the user clicks the command button and is returned
to the previous page before the page has been completely built,  I
find the PERL script is still running. It eventually dies (20 - 30
seconds). I'd like to kill the process as soon as the user returns to
the original page.

How do I determine when that happens?

I'd also like to be able to delete temp files that are  deleted when
the PERL script normally completes.

Thanks for your help!

CGIs don't interact with users. Their output goes to
a web server and they exit. If you are trying to keep
the CGI running while a user decides what to do, you
are doing it wrong.
 
T

Tim Greer

Petyr said:
I have a PERL-CGI application. I gather input from user, start PERL
script and build a new web page based on input. At the top of the
newly created page is a command button to return the user to the
previous page. If the user clicks the command button and is returned
to the previous page before the page has been completely built, I
find the PERL script is still running. It eventually dies (20 - 30
seconds). I'd like to kill the process as soon as the user returns to
the original page.

How do I determine when that happens?

I'd also like to be able to delete temp files that are deleted when
the PERL script normally completes.

Thanks for your help!

It sounds like a bug in the script. CGI doesn't work that way, it can't
know if the end-user's browser is still loading the data that's output
from the script or not. You can perhaps add some restrictions within
the script itself to die if it's running too long (if you can check
that within the script), or from the web server (setting limits on run
time, cpu, memory usage and concurrent processes), or some tool to
monitor it and act on the run time or resource usage.

If you use some sessions, you could try and track the user returning to
the original page and then use that information to see if a process is
running that they've spawned and use that to kill it (if you have the
permission and ability to do so on your system). There are likely
several ways to approach the idea of this, but it doesn't work
directory with the browser/client. More information would be needed
about what this is doing, some code examples (perhaps) and the options
you have available.

As for deleting files, simply make some effort in the script to do all
of the checks you need to do, before it ends, and at the last stage (or
where appropriate) have it safely remove the temporary files (before
the script ends).
 
T

Tim Greer

Petr said:
You can set some $SIG{} perl variables to you own routine. I'm not
sure if this is exact but possible when user click back button then
Appache server (or other web server service) send TERM or QUIT signal
to your perl proccess. When you have $SIG{} variable redirected to
your routine then you can do something you need.

#!/usr/bin/perl
use strict;
# .....
$SIG{'QUIT'}=sub {errexit("SIG-QUIT")};
$SIG{'TERM'}=sub {errexit("SIG-TERM")};
# .....

sub errexit
{
my $signal = shift;
# you can write $signal to the log file if you need

# you can unlink some files;

exit 0;
}

Those (signals) aren't sent or captured from the browser. Do you meant
to suggest some alarm for the run time or something?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top