Starting a new script to run in BG 
Author Message
 Starting a new script to run in BG

     I am running AS Perl on WinNT 4.0.  I am hoping there is solution
to my dilemma.  I would like to have a webpage (Perl Script) load and
when it does, spawn another process (Perl script, or subroutine) that
runs in the background until it finishes.  Basically, the first time
each day that a certain script on my site is called up, I want it to run
a maintenance script.  I don't want this to run and have the user wait,
however, as it could take a while.
    Any suggestions here?  I hope I made sense.  Please CC me on a
response.  I only get the digest.  Thanks!

-Brandon



Thu, 25 Jan 2001 03:00:00 GMT  
 Starting a new script to run in BG
[courtesy copy e-mailed to author(s)]


Quote:
>     I am running AS Perl on WinNT 4.0.  I am hoping there is solution
>to my dilemma.  I would like to have a webpage (Perl Script) load and
>when it does, spawn another process (Perl script, or subroutine) that
>runs in the background until it finishes.  Basically, the first time
>each day that a certain script on my site is called up, I want it to run
>a maintenance script.  I don't want this to run and have the user wait,
>however, as it could take a while.
>    Any suggestions here?  I hope I made sense.  Please CC me on a
>response.  I only get the digest.  Thanks!

Can you do a fork() call on your WinNT machine?

At the top of your script:
$SIG{CHLD}='IGNORE';

Then wherever else in your script (probably at the end);

if ( .. check time and see if it already ran today ...) {
    if ($child = fork()) {
        print STDERR scalar localtime(time),
            "Running cleanup (PID: $child) - should be logged in HTTP error-log file.\n";
        exit();
    } else {
        cleanup();      # or exec("cleanup.pl");
        exit();
    }

Quote:
}

--

NDUS UNIX SysAdmin        http://www.nodak.edu/~nem/
"Perl did the magic.  I just waved the wand."


Thu, 25 Jan 2001 03:00:00 GMT  
 Starting a new script to run in BG

Date: Sun, 09 Aug 1998 17:35:58 -0600

Quote:

>       I am running AS Perl on WinNT 4.0.  I am hoping there is solution
>  to my dilemma.  I would like to have a webpage (Perl Script) load and
>  when it does, spawn another process (Perl script, or subroutine) that
>  runs in the background until it finishes.  Basically, the first time
>  each day that a certain script on my site is called up, I want it to run
>  a maintenance script.  I don't want this to run and have the user wait,
>  however, as it could take a while.

I think you shouldn't "spawn" anything. Just display the page (script
does this, doesn't it?) and let the script continue and do their "daily"
job. Don't forget to apply some "locking/loging" logic to prevent more
then one running script(s) to try to do the same job in the same time or
more than once a day.

CGI script just produce an HTML output and continues.

Personaly, I make my clean-up job(s) every time the script is called. For
example, the expired shopping-carts are deleted (if any) at every script
call. I even don't bother if another script instance is making clean-up
at the same time. Let it be! However, this is a true clean-up - i.e. just
deleting. If something is to be logged, modified, etc. the logic would be
much more complicated.

--
=== PLEASE REMOVE ## FROM MY EMAIL ADDRESS! GUESS WHY :-) ===

Plamen Petkov

http://bgbook.hypermart.net



Sat, 27 Jan 2001 03:00:00 GMT  
 Starting a new script to run in BG


Quote:

>Date: Sun, 09 Aug 1998 17:35:58 -0600

>>       I am running AS Perl on WinNT 4.0.  I am hoping there is solution
>>  to my dilemma.  I would like to have a webpage (Perl Script) load and
>>  when it does, spawn another process (Perl script, or subroutine) that
>>  runs in the background until it finishes.  Basically, the first time
>>  each day that a certain script on my site is called up, I want it to run
>>  a maintenance script.  I don't want this to run and have the user wait,
>>  however, as it could take a while.

>I think you shouldn't "spawn" anything. Just display the page (script
>does this, doesn't it?) and let the script continue and do their "daily"
>job. Don't forget to apply some "locking/loging" logic to prevent more
>then one running script(s) to try to do the same job in the same time or
>more than once a day.

>CGI script just produce an HTML output and continues.

Make sure you have command buffering turned on.  And realize that the
server may kill processes which hang around "too long".

I think spawning is cleaner, if you can do that under NT. See Randal's
column on the subject:

        http://www.stonehenge.com/merlyn/WebTechniques/col20.html

Quote:
>Personaly, I make my clean-up job(s) every time the script is called. For
>example, the expired shopping-carts are deleted (if any) at every script
>call. I even don't bother if another script instance is making clean-up
>at the same time. Let it be! However, this is a true clean-up - i.e. just
>deleting. If something is to be logged, modified, etc. the logic would be
>much more complicated.

cron is simple, and much more efficient.

--

The first condition for the establishment of perpetual peace is the
general adoption of the principles of laissez-faire capitalism.
  - Ludwig von Mises



Sat, 27 Jan 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. start process remotely, in bg with Net::Telnet doesn't work

2. run script from script - new process?

3. Can't start new process from Perl CGI script

4. Auto-Run a Perl Script on start-up

5. Starting a new process in a new window

6. New to Perl - script runs in IDE but not on server

7. Run a new page from the output of cgi script

8. calling a new webpage after perl script has run

9. A newer version of the script (re: New Mail script)

10. Debug a forked/exec Perl script started from another Perl script

11. perl scripts hangs while starting httpd server within other script

12. PID's, killing processes when new one starts - revisited

 

 
Powered by phpBB® Forum Software