xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Hi esteem monks!

I have done a snippet for checking oracle data files by dbv in parralle.I'm afraid trying it in haste maybe cause unpredictable aftermath.(In fact,the system I have been maintaining crushed last month because of my trying of another script.I don't want to be fired due to perl :) So I should find a good and safe way to check my script.Adding print,perl -d or others? Please help me!

Below is my code:
#!/usr/bin/perl use strict; use warnings; open (FH,"<xyf.lst") or die "error!! $! \n"; my @file_lists = <FH>; my $files = \@file_lists; m_fork(5,$files,\&dbv_check); sub dbv_check { my ($file,$logfile)= @_; system ("dbv","file=$file","blocksize=8192","logfile=$logfile"); } sub m_fork { my ($max,$file_list,$dbv_command) = @_; my $count = 0; foreach my $file_name (@$file_list) { wait if $count>$max; die "error\n" unless defined(my $pid = fork()); exit $dbv_command->($file_name,$count) unless $pid; $count ++; } }
Thanks in advance!


I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Replies are listed 'Best First'.
Re: How debug
by kyle (Abbot) on Mar 20, 2007 at 02:29 UTC

    For testing code that forks, you might try replacing dbv_check with something that doesn't do a whole lot like:

    sub fork_test { my ($file,$logfile)= @_; print "I'm working on file '$file', logfile '$logfile'.\n"; sleep 3; print "I'm done working.\n"; }

    Then call m_fork with a relatively short file list (say 10 or 15 elements).

    If it forks too much, you'll see lots of "I'm working" before seeing any "I'm done working." If it's working as you think it should, you should get five "I'm working" and a pause before anything else.

    The code in m_fork increases $count but never decreases it. You might want to do something like:

    while ( $count > $max ) { wait; $count--; }

    One other suggestion: if you can't fork, it would be good for the error message to say why.

    die "Can't fork: $!\n" unless defined(my $pid = fork());
      Thanks for your answer!

      Changing system func to print would be a good idea.Let me try.But no offense to you,I don't think I need to add $count -- statement.What I mean in this snippet is waiting until a child process complete.

      PS.your XP chart is very interesting! how do it? :)

      I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
Re: How debug
by jesuashok (Curate) on Mar 20, 2007 at 02:39 UTC
    you can write the follwing messages and get to know more from the LOG file.
    • Create a log file when the program Starts ( PID of the parent Process )
    • Forked PID and the corresponding PPID
    • ended PID
    • opened file names and log filenames
    Through the above you can come to know what is happening inside your perl snippet.


    hmmm ....let me think what did I said