Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help setting up a basic fork in Win32.

Status
Not open for further replies.

Numbski

MIS
Mar 27, 2001
56
US
I have no idea if the fact that I'm doing this from a Win32 system has any bearing on this or not, but it's really starting to drive me up a wall. Here's my situation:

I'm writing to applications that are run by an end user who has installed ActivePERL and a web server on their machine. So the server and the client are the same box, the application is being access via The problem I'm running into is that on a few functions the time it takes to complete is far longer than the timeout on the web server is set to. Rather than having the end user mess with the web server settings, I'd rather have it fixed within the script. From what I can tell, the way to do this is to fork the script, have the child do all the work while the parent prints HTML to the client stating that there is work being done, and having it meta refresh every few seconds. After the child is finished have it exit, and then the parent detects that the child is done and prints new HTML stating that the child is done and the program can continue.

I've tried many different types of syntax and I can't get any of them to take. I've seen several code samples, but it just won't fly. In pseudo code here's what I'm looking for:

Code:
Fork the script
if (parent){
     print html that refreshes "work in progress";
     when child is done, print html "work done, continue?";
}

elsif(child){
     do lots and lots of work taking lots of time;
     exit();
}

At least I *think* that's how it goes. Anyone out there able to help me?
 
Ok.

fork() on winxx is a bit wierd and you need to check the documentation, of your version of Perl, to see what will work.

Having said that:

This is a generic fork script without error checking

if (fork()){
print $html_that_refreshes_work in progress;
# when child is done, print html "work done, continue?";
} else {
# do lots and lots of work taking lots of time;
sleep(300);
exit();
}

not so different from your code really

however...... how will you tell when your child process has completed?

Is that the problem you're having? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Well, I can't say that it is...the problem I've had is that every example I've come across has run me blank. I'd try to set the 'work' part of my script as either parent or child, and no matter what my "Please wait" part of the script never displays. Instead I get the error from the web server that the server is busy, try again later, in other words, the server timed out on the operation. Essentially what I want to see if "Please wait" and here the hard drive going nuts trying to do all this stuff (and believe me, there is a LOT going on...), and it just never happens.

You're right though, I'm not sure how the parent process would know if the child is done, other than idly throwing in a wait();. To be honest I would never have wanted to use a fork if I thought I could reliably 'shut off' the timeout on a cgi execution. This is for the best I'm sure. Basically the effect I'm looking for is display something in the interim while all these things are done in the background, and when they are done display an indication that it's done and one may proceed. I've read the Win32 documentation and ActivePERL is compiled to support this, but I'm just not getting the syntax right...
 
Sorry for the delay in getting back to you -- I've been a bit busy :)

Let's try and break the problem down a bit.

Have you tried running a test script from the command line without involving your web server? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Yes, but if that were the case, i wouldn't need the fork operation. The point of forking the program (and if I'm understanding it right, running an exact copy of the script with a different PID) is so that I can satisfy the web server's need to have a text reply AND take all the time I need to do these operations in the background. If I attempt this without the web server, how will that work? I mean only one thing can talk to the console at a time? I'm presuming I'd just hear a bunch of grinding and get a print at the same time?
 
I'm sorry -- I didn't make myself clear.

I mean that your first step should be to see that fork() works properly on your platform. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top