I would like to have my program initiate another program during the course of its execution. my code writes some files to disk, and I'd like to spawn off another program to merge those files. My main program keeps running while the merging occurs in the background. I was recommended fork and exec as a tool for this job, but I've never used these before, and can't really say that I understand how they work. here is what my routine is:
sub logMergeManager
{
my $writeCounter = $_[0];
#a trick for implementing logarithmic merging
$level = 1;
for(my $ct = 2; $ct <= $writeCounter; $ct*=2)
{
if($writeCounter%$ct == ($ct -1) && $writeCounter > 0)
{
push(@forkArray, $level);
push(@forkArray, $writeCounter);
my $nextMerge = ($ct/2);
push(@forkArray, $nextMerge);
}
else
{
last;
}
$level++;
}
if(fork())
{
for(my $ct = 0; $ct <= $#forkArray; $ct+=3)
{
my $level = $forkArray[$ct];
my $mergeLast = $forkArray[$ct+1];
my $mergeFirst = $forkArray[$ct+2];
my $dir = '/data/c6/indexes/';
my $name2 = $dir.$level."_indexBlock_".$mergeL
+ast;
my $name1 = $dir.$level."_indexBlock_".$mergeF
+irst;
exec "./indexes/merge2.pl $name1 $name2";
}
}
}
almost certainly this is a terrible example of perl code, but i'm trying! when i run my code since i've implemented this, almost right away everything shuts down, all memory is used and the computer freezes, only to be saved by ^C. can anyone tell me what i'm doing wrong? forgive my noob-ness.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.