Re: How to run a process in background?

2002-10-09 Thread Octavian Rasnita

Hi and thank you.

I want to create a script that is activated when someone visits a .shtml
page.
That script is launched by a server side includes line.

The script need to check if a database was updated, and send mail to more
email addresses about this.
This mailing process might take a long time, and I don't want the page
visitor to need waiting until the mailing is complete.

The server is not mine and I can't use other methods to check the database
from time to time and send mail, so the visitor is not interested in sending
those emails at all.
They don't even know that a mailing process is started by them.

So I don't need to get the results from the child process.
If I need this, I might print the results to a log file.

I want the child process to continue working and the web page to finish
loading after initiating the process, not waiting for it.

I also want the child process to terminate fine without creating zombies.

It is pretty hard to understand zombies very well, because I don't know Unix
too well.

Thank you.

Teddy's Center for the blind: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

- Original Message -
From: "zentara" <[EMAIL PROTECTED]>
To: "Octavian Rasnita" <[EMAIL PROTECTED]>
Sent: Wednesday, October 09, 2002 2:22 PM
Subject: Re: How to run a process in background?


On Wed, 9 Oct 2002 18:10:42 +0200
"Octavian Rasnita" <[EMAIL PROTECTED]> wrote:

>I've tried the script sample and it works fine but it doesn't work with the
>following line:
>fork && exit;
>
>I need to type just:
>fork;
>
>... because otherwise the browser (IE) keeps "Opening page...".

The script was just to demonstrate what closing STDOUT does to
release the browser.

>Can you tell me, is it OK if I use the script with the line for closing
>STDIN, STDOUT, and STDERR uncommented?

Sure, but your browser will stay connected as long as the child process
is running, or the server times out.  Wasn't that your original problem?

>
>In this case all works fine. Is it any danger to create zombies?

Zombies could get created if you kill off the parents before the children.

>And what do you recommend, to use exec, or system?

What are you trying to do exactly?
system runs and returns results to the calling process, when you do an
exec, the calling process terminates and the exec'd process goes on.

>I don't need to get the output from the child process, but I don't know how
>is better, to let the parent process to wait for the child, or not.

If you don't need output from the child process, what is the child process
doing?

There is alot of intricacies with forking, and I can't say what you should
do
without know what you want to do.

It would be best for you to post your code to the list, many brains are
better
than one. Post what you are trying to do, not just generalized questions
about
forking in a cgi.









--
use Perl;  #powerful programmable prestidigitation



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to run a process in background?

2002-10-09 Thread Octavian Rasnita

Hi and thank you.

I've tried the script sample and it works fine but it doesn't work with the
following line:
fork && exit;

I need to type just:
fork;

 because otherwise the browser (IE) keeps "Opening page...".

Can you tell me, is it OK if I use the script with the line for closing
STDIN, STDOUT, and STDERR uncommented?

In this case all works fine. Is it any danger to create zombies?

And what do you recommend, to use exec, or system?
I don't need to get the output from the child process, but I don't know how
is better, to let the parent process to wait for the child, or not.

Thank you.

Teddy's Center for the blind: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

- Original Message -
From: "zentara" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 30, 2002 3:17 PM
Subject: Re: How to run a process in background?


On Sun, 29 Sep 2002 16:40:07 +0200, [EMAIL PROTECTED] (Octavian Rasnita)
wrote:

>I want to make a script that is activated from a browser but it might take
a
>long time to send all the messages using the Net::SMTP.
>
>So I think that it could be a good idea to make a background process to run
>it.
>
>Can you give me some hints about how I should use the fork, to run the
>process in background?

Your biggest problem is to close the pipes to apache from the forked
children, else your clients will see their browser's hang.
Merlyn has a good column on this at www.stonehenge.com  column 20.

Here is a simple example to demonstrate the problem.
Make up some long process to test this with, like while(1){sleep(1)}
Then try running it as a cgi script with and without the line which
closes STDOUT, STDIN, and STDERR.  With it commented out,
your browser will hang.

##
#!/usr/bin/perl
use warnings;
use strict;

$| = 1; # need either this or to explicitly flush stdout, etc.
# before forking
print "Content-type: text/plain\n\n";
print "Going to start the fork now\n";

fork && exit;

#try running with the following line commented out
close STDOUT;close STDIN;close STDERR;

exec('./fork-long-process-test-process') || warn "funniness $!";

#if you use system here, instead of exec, the parent process
#hangs around for child to exit, even though the cgi exits.
#



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to run a process in background?

2002-09-30 Thread zentara

On Sun, 29 Sep 2002 16:40:07 +0200, [EMAIL PROTECTED] (Octavian Rasnita)
wrote:

>I want to make a script that is activated from a browser but it might take a
>long time to send all the messages using the Net::SMTP.
>
>So I think that it could be a good idea to make a background process to run
>it.
>
>Can you give me some hints about how I should use the fork, to run the
>process in background?

Your biggest problem is to close the pipes to apache from the forked
children, else your clients will see their browser's hang.
Merlyn has a good column on this at www.stonehenge.com  column 20.

Here is a simple example to demonstrate the problem.
Make up some long process to test this with, like while(1){sleep(1)}
Then try running it as a cgi script with and without the line which
closes STDOUT, STDIN, and STDERR.  With it commented out,
your browser will hang.

##
#!/usr/bin/perl
use warnings;
use strict;

$| = 1; # need either this or to explicitly flush stdout, etc.
# before forking
print "Content-type: text/plain\n\n";
print "Going to start the fork now\n";

fork && exit;

#try running with the following line commented out
close STDOUT;close STDIN;close STDERR;

exec('./fork-long-process-test-process') || warn "funniness $!";

#if you use system here, instead of exec, the parent process
#hangs around for child to exit, even though the cgi exits.
#



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to run a process in background?

2002-09-30 Thread fliptop

On Sun, 29 Sep 2002 at 16:40, Octavian Rasnita opined:

OR:Can you give me some hints about how I should use the fork, to run the
OR:process in background?

have you read

perldoc -f fork

yet?  if so, what part of that do you not understand?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




How to run a process in background?

2002-09-29 Thread Octavian Rasnita

Hi all,

I want to make a script that is activated from a browser but it might take a
long time to send all the messages using the Net::SMTP.

So I think that it could be a good idea to make a background process to run
it.

Can you give me some hints about how I should use the fork, to run the
process in background?

Thank you.

Teddy's Center: http://teddy.fcc.ro/
Mail: [EMAIL PROTECTED]

Teddy's Center: http://teddy.fcc.ro/
Mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]