How do I stop this process once I start it from the web from a cgi script?

S

Scott Clay

This is as simple as I can write this for now. My program is a lot more
complicated using telnet objects and logging into a server and collecting
logs from it.
I've broken it down into this.

I have a simple form on a solaris web server. I'm trying to control the
program with 2 buttons. A start & stop button. On clicking the start button,
I enter an infinite while loop. I can kick out of the loop if a global
variable is set to stop when clicking on the stop button. However, I 'm
finding out that the start button is actually kicking off it's on process on
the machine. Upon clicking the stop button, this process remains.

zrc2s0ry-261> ps -ef | grep tricky
mtxweb 11896 16920 0 14:47:40 pts/20 0:00 vi tricky2.cgi
mtxweb 28303 6556 0 15:04:12 pts/4 0:00 grep tricky
mtxweb 28291 11896 2 15:04:04 pts/20 0:01 /usr/bin/perl tricky2.cgi

I've browsed the ipc perldoc, but not quit sure I really understand what is
going on. What methodology do I need to use, to have the 2nd instance of the
cgi script pass the global variable in which I'm trying to control the
program to the 1st instance?

Here is the sample. Just starting counting by 1, and print the value,
forever. When the stop button is clicked, I want the first process to finish
by exiting the while loop and return control to the user.

#!/usr/bin/perl

use CGI;

$query = new CGI;

$done4 = 'Stop';

print $query->header;
print $query->start_html("Counter");
print "<h1>IPC</h1>\n";

&print_prompt($query);
&do_work($query);
&display_count();

print $query->end_html;

#########################
sub print_prompt
#########################
{
my($query) = @_;
print $query->start_form;

print "<p>counting by 1s<br>";
print "<br>";

print $query->submit('Action', 'Start');
print $query->submit('Action', 'Stop');
print "<br>";

print $query->endform;
print "<hr>";
}

#########################
sub do_work
#########################
{
my($query) = @_;

my(@values,$key);
print "<h3>Settings</h3>";

foreach $key ($query->param) {
print "<strong>$key</strong> -> ";

if ($key eq 'Action') {
$done4 = $query->param($key);
}
@values = $query->param($key);
print join(", ",@values),"<br>\n";
}
}

#########################
sub display_count
#########################
{
$i = 1;
print "DONE: ", $done4;
print "<br>";

while (1) {
last if ($done4 eq 'Stop');
print "I= ", $i++;
print "<br>";
}
}

Thanks,
Scott
(e-mail address removed)
 
A

Alan J. Flavell

On Thu, 24 Mar 2005, Scott Clay wrote:

| How do I stop this process once I start it from the web from a
| cgi script?

In a simple minded sense, you don't. The CGI paradigm involves
triggering execution of a server-side process, and the next that you
get to hear of it (unless it takes so long that it times-out) is when
it completes and returns an answer to you.

Anything beyond that is a bit of a challenge, and needs careful system
design from the CGI point of view. The Perl language plays only a
peripheral role in that - and basically puts your problem off-topic
for the Perl language group, until you at least have a process design
which fits into the CGI paradigm. Then, I'm sure the hon Usenauts
would be happy to offer Perl-specific advice, but from long experience
of this group I can say they don't care for CGI-specific questions
here. See comp.infosystems.www.authoring.cgi (beware the
automoderation bot).
This is as simple as I can write this for now. My program is a lot
more complicated using telnet objects and logging into a server and
collecting logs from it.

What impression did you get from the CGI FAQ (I'm thinking of Nick
Kew's, if we're in any doubt), where it discusses dealing with
long-running processes?
I have a simple form on a solaris web server. I'm trying to control
the program with 2 buttons. A start & stop button. On clicking the
start button, I enter an infinite while loop. I can kick out of the
loop if a global variable is set to stop when clicking on the stop
button. However, I 'm finding out that the start button is actually
kicking off it's on process on the machine. Upon clicking the stop
button, this process remains.

You know, this somewhat reminds me of the media-on-demand server that
I was messing with in 1994 or so. The first CGI call spawned off a
sub-process whose job was to persist, and send media streams to the
client. Other CGI calls invoked transient processes whose job was to
signal the spawned sub-process to take certain actions, such as pause,
continue, rewind etc. and finally quit. Google on media-on-demand,
kth and klemets for the design that I was following back then.

Of course, the long-running process had to be equipped with some kind
of machinery to terminate itself when the user simply lost interest
and closed their browser.

None of this is specific to Perl, even if that media on demand server
design which I was working from had been written in Perl4 and was, in
a sense, the very thing that triggered me to start working in Perl,
back then ;-)
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top