The solution is to open a shell script with a pipe and send it the
commands to be executed.  That way no new shell is opened for each
command and McAfee is quiet:

        # open shell with pipe and turn off buffering
        open (OPSH, "|-") or exec ("./my.sh 01 >opsh1.log 2>&1");
        $savefh = select (OPSH); $|=1; select $savefh;

        # send command to execute my.exe with parameters
        printf (OPSH "./my.exe @params\n");

The pipe is one-way only so that leaves the problem of knowing when
the compiled program is done.  For that, the shell touches a file,
my.sig, after the command is complete.  The perl script does one
intial long sleep followed by a loop with a tiny sleep:
        # fractional second sleep
        select (undef, undef, undef, $optsleep);
        $optsleepct=0;
        while ( !e my.sig ) {
            $optsleepct += 1;
            select (undef, undef, undef, .001);
            }
        ... recalculate $optsleep to minimize the number of loops ...

I tried using SIG(ALRM) to communicate the completion but it was
really slow.  The above method racks up some cpu and lots of 'I/O
Other' (so that is what !e does!) but runs pretty fast.

Another improvement to the process was made when I realized that the
shell could submit jobs to the background.  The perl script was
reprogrammed to divide the executable's work in two, the shell runs
them both in the background and does a 'wait' before touching my.sig.
About a 30% improvement in speed.  Dividing the work into >2 parts ran
slower due to overhead in the executable.

Now we're cranking!

Paul K


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to