Forking in Window enviroment

From: Herman Chan (c24chan_at_yahoo.ca)
Date: 10/08/03


Date: 8 Oct 2003 14:19:29 -0700

Hi:

I have the following script

==========================================

#!D:/Perl/bin/Perl.exe -w

use strict;
use CGI ":standard";
$| = 1;

my $MYFILE = "D:\\Apache\\logs\\mgmtwrkstn\\lucky.txt";

if (param("monitor")) {
        &monitor();
} else {
        if (fork) { # only need to fork for IE
                print redirect(-uri => url() . "?monitor=yes",
-nph=>1);
        } else {
                &do_stuff();
        }
sub monitor
{
        my $html = &draw_page();

        if (defined $html) {
                print header(-refresh=>1, -nph=>1), $html;
        } else {
                print header(-nph=>1), &goodbye();
        }
}
sub goodbye
{
        return start_html(-title=>"Goodbye!") . h1("Goodbye!") .
end_html();
}
sub get_number
{
        open NUMBER, "<$MYFILE" or return undef;
        my $number = @glo;
        close NUMBER;

        return $number;
}
sub draw_page
{
        my $number = &get_number();

        return (defined $number) ? start_html(-title=>"Your Lucky
Number") . p("Your lucky number is $number.") . end_html() : undef;
}

sub do_stuff
{
        for my $i (1 .. 10)
        {
                open NUMBER2, ">$MYFILE";
                print NUMBER2 $i;
                close NUMBER2;

                sleep 1;
        }

        unlink $MYFILE;
}

=========================================================

What this script essentially do is that it forks a child process to
write 1 to 10 on some file, while writing it, the parent process will
refresh the page every second to read the content of that file. This
script is orginally from
http://hypernews.ngdc.noaa.gov/HyperNews/get/webscience/2/6/1.html?nogifs

It works under Unix environment with apache. However, when I run this
script in W2K and apache 1.3.x. It doesn't work. It seems like that
the child process is locking the files its writing to and the parent
process can't go into it. Therefore, the parent process doesn't
refresh the page until the child process unlink ("delete") the file.
Can anyone help me on this one? I am a newbie on Perl and CGI and I
want to continuosly monitor some background job on a web page.

Thanks
Herman



Relevant Pages

  • CGI autoflush in Window
    ... sub monitor ... What this script essentially do is that it forks a child process to ...
    (comp.lang.perl)
  • Re: Detecting is hyperthreading is enabled with WMI?
    ... It is too bad that WMI does not give this info. ... have to be done to the script. ... Public Sub DisplayProcessorInfo ... dim ProcessorSet, Processor ...
    (microsoft.public.windowsxp.wmi)
  • Cant make this page work
    ... I can't make this script work properly. ... The script at the bottom of the html page ... Does someone have a perl ... sub output_trace_headers { ...
    (comp.lang.javascript)
  • Re: Maybe I should try a different approach
    ... entire time my script is running, then have it close when my script is done and maybe have some dots keep adding to the text message until the script is fully completed? ... ' The "Three Ugly Hack" Script, ... Sub oATO_vbTimerEvent' timer event handler... ... Public Property Let Left ...
    (microsoft.public.scripting.vbscript)
  • Re: Win32_Product doesnt list all installed Applications
    ... 'Must have ADSI and WMI installed on PC running script. ... CONST ForReading = 1 ... Sub Connect ... strHTML = "Smoke'm if you Got'em" ...
    (microsoft.public.windows.server.scripting)