I've read a lot of sections on fork but can't seem to find what I am looking for. I created a program in a pTk. What I am trying to do is basically get the parameters that I need to pass to a shell script, kick off the shell script and still be able to use the window. The Function that RUN's the shell script is set up like:
sub run_program { my $inputfile; my $cmdline; my @running; my $tot_running; my $tot_files; my $tot_done; my $segment; my $locdir; $step++; # step 1 run input command print STDOUT "Running input command $in_cmnd\n"; system ("$in_cmnd"); print STDOUT "Running Script\n"; $step++; # Run as child process so can still use window????? unless(fork) { JOBS: for(;;) { @running=glob("$base/running.$pid.???"); $tot_running=@running+0; $tot_files=0; $tot_done=0; JOB: foreach $inputfile (glob("$in_dsn.???")) { $tot_files++; $segment=substr($inputfile,-3); # it's done if (open CHECK, "$base/done.$pid.$segment") { unlink "$base/running.$pid.$segment"; unlink "$base/done.$pid.$segment"; unlink "$inputfile"; $tot_done++; close CHECK; next JOB; } if (open ERROR, "$base/error.$pid.$segment") { system("rm $base/running.$pid.$segment 2> /dev/null"); print STDOUT "There was an error running segment $segme +nt\n"; error_message("There was an error running segment $segm +ent\n"); $tot_done++; close ERROR; next JOB; } if (open RUNNING, "$base/running.$pid.$segment") { next JOB; close RUNNING; } # launch the process if ($tot_running < $num_process) { $locdir = "/\U$mnem/$pid/$segment"; system("mkdir -p $locdir"); $cmdline="cd $locdir ;nohup $script $pid.$segment $pid. +$segment \L$filter\E 01 $no_mnths N >stdout 2>stderr &"; print STDOUT "Running\n$cmdline\n"; system("$cmdline"); system("echo xxx > $base/running.$pid.$segment"); $tot_running++; } } # for each file # break out of the loop when all files are processed last JOBS if $tot_done == $tot_files; sleep(10); } $step++; # step 3, run output command print STDOUT "Running $out_cmnd\n"; system("$out_cmnd"); $step++; # step 4, merge reports print STDOUT "Mergeing reports\n"; &merge_forms; print STDOUT "\nProcess complete\n\n"; } # end of fork }
It prints out Process complete, and the script runs fine but I keep getting this error:
Process complete X Error of failed request: BadIDChoice (invalid resource ID chosen fo +r this connection) Major opcode of failed request: 53 (X_CreatePixmap) Resource id in failed request: 0x100004f Serial number of failed request: 25739 Current serial number in output stream: 24474
I believe it has something to do with the fork but not quite sure, any ideas!!!! Thanks, Tom

In reply to Running multiple scripts using fork by enanrum

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.