First of all, I'm on a unix box, running apache with perl 5.6.1.

I've been banging my head for three days trying to figure this out and can't manage to. What I have is a cgi that basically asks for usernames, devices names, passwords, etc and then passes those items to other pl files that actually do a lot of ssh connections to pull data from remote routers and switches. This is somewhat time consuming and if I just try to do it straight from the script it always times out and never finishes. So I heard a rumor that I could fork some child processes, the browser would just tell the users "Ok, its processing, it'll be done soon" and be done with it, close the browser if they want or whatever because the other scripts produce no output, they actually email the results to the user after it has been processed. But I can't seem to figure out how to fork 7-8 processes at the same time. My code is similar to this:

if (defined(param('subbed'))){ $pid = fork(); if(! $pid){ exec ("./gw1.cgi userid=" . param('userid') . " gw1=" . param( +'gw1')); exec ("./gw2.pl userid=" . param('userid') . " gw2=" . param(' +gw2') . " pswd=" . param('pswd') . " enable=" . param('enable')); } } else { PrintIndex(); }

When I launch off the page in browser, input the required data in the form and hit submit it just sits at a white page waiting until the script is completely done, which 9 times out of 10 times out. When I try to run it straight off the server command line through ssh it seems to work but doesn't launch off the second exec command. I only have two exec commands right now but when all is said and done I should have 6-7 different scripts that need to be launched off.

Can someone please help me with this as I just don't know how to proceed, if forking isn't my best option, let me know another, but I'm just stuck in a rut and can't get out.


In reply to Need assistance with forking multiple child processes by jmclark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.