Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Using parent and child processes in perl

by rjt (Curate)
on Jul 14, 2013 at 12:50 UTC ( [id://1044221]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using parent and child processes in perl
in thread Using parent and child processes in perl

The actual computation takes about 4-5 minutes and I am using a RedHat Linux OS. I return some 1000 rows of data.

Unless the rows are huge, 1000 rows is not a lot of data, so you should be OK, there. The original issue is almost certainly the computation time. Redhat definitely supports fork, which is good.

So you are saying, in the child I store the result in a global variable($temp) and in the parent,I will have only one line that redirects the url to another cgi script with this $temp as parameter. i.e

No. Once the fork() takes place, the parent and child are separate processes. Updates to $temp (or any other memory, for that matter) in one process will not affect the other process whatsoever. Then, the parent just prints the redirect header with the display_id and exits immediately. In five seconds, when the browser sends a request for the display_id, the server creates another entirely new process to service the request.

That's why I suggested a temporary file (or temporary database storage); you need some way to keep persistent state (and know where to find that state), because the client connection is created and destroyed every few seconds when the refresh hits. It's a simple form of IPC.

But how will I know when $temp is populated completely? :(

That's up to you, but one simple method is to designate an "end of transmission" (EOT) marker that will never appear in the normal output. In the child, print the EOT to the end of the same temp file once the operation finishes. In the other CGI that reads the display_id file, if you see that EOT, you know the job has finished, and can take whatever action is appropriate.

Replies are listed 'Best First'.
Re^4: Using parent and child processes in perl
by Anonymous Monk on Jul 14, 2013 at 18:47 UTC
    Thanks a lot! One last question, instead of redirecting, I would also be able to process the content of the $tempfile inside the parent itself, won't i? Once again, thanks a bunch!

      You would then still have the same problem you started with: a single 4-5 minute HTTP request. The whole point is to have each request finish quickly, which is how we'll avoid the server error you mentioned in the OP.

        Okay, so I redirect from parent and read the $tempfile in a new script then? Thanks a lot!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1044221]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found