issue with multiprocess - fork

Discussion in 'Perl Misc' started by friend.05@gmail.com, Aug 6, 2009.

  1. Guest

    My script is using fork so there are child processes. Sometimes my
    script runs properly and output is correct. But sometime my script
    gets stuck just after exiting child process.

    Below is psudo code. (not sure if this helps, it is juist snap shot)

    foreach my $w (keys %worklist) {
    my $child;
    unless ($child = fork()) {
    die("connot for: $!") unless defined $child;

    foreach my $file (@{$worklist{$w}}) {
    #reading files processing of data and
    creating hash tables.
    }

    #ouput files from hash tables. outfile files will be
    for each child.

    print "Worker $w $$ exiting\n";
    #child
    exiting
    (#it gets stuck after printing this statement)

    exit;
    }
    push(@workers, $child); #array of child PID

    }

    #wating for each child to finish.
    foreach my $pid (@workers) {
    $s = waitpid($pid, 0);
    print "$s finished\n";

    }


    The freeze happens sometimes.

    And I check the trace(truss -p on sun). I found that sometimes one of
    the child goes to sleeping and parent is still waiting for that child
    exit status. But it never gets that bcoz child is sleeping.

    And suggestion what can be problem or else how can I debug more.

    Thanks
    , Aug 6, 2009
    #1
    1. Advertising

  2. wrote:
    > My script is using fork so there are child processes. Sometimes my
    > script runs properly and output is correct. But sometime my script
    > gets stuck just after exiting child process.


    Asking the same question under a different subject line is more likely
    to annoy the people you want to help you, than it is to get you more help.

    Threads exist for a reason.

    Xho
    Xho Jingleheimerschmidt, Aug 7, 2009
    #2
    1. Advertising

  3. Guest

    On Aug 7, 8:29 am, Tad J McClellan <> wrote:
    > Xho Jingleheimerschmidt <> wrote:
    > > wrote:
    > >> My script is using fork so there are child processes. Sometimes my
    > >> script runs properly and output is correct. But sometime my script
    > >> gets stuck just after exiting child process.

    >
    > > Asking the same question under a different subject line is more likely
    > > to annoy the people you want to help you, than it is to get you more help.

    >
    > Indeed, as I had killfiled this OP in April when he crossposted
    > the first time.
    >
    >    http://groups.google.com/groups/search?as_umsgid=74405uF119t50U2@mi...
    >
    > I thought at the time that it was perhaps a bit harsh to banish
    > him to perpetual invisibility, but I did it anyway.
    >
    > Seeing that he still does it after being warned about it makes
    > me feel better about my original decision.
    >
    > --
    > Tad McClellan
    > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


    sorry about that. I thought it 3days so people might not see the
    thread and I am stuck at that problem. so I posted new thread.

    will be careful next time
    , Aug 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Shestero

    stream in multiprocess (multithread) apps

    Michael Shestero, Dec 19, 2003, in forum: C++
    Replies:
    4
    Views:
    523
    Michael Shestero
    Dec 19, 2003
  2. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    562
    Eric Snow
    Jan 8, 2009
  3. Replies:
    4
    Views:
    254
    TennesseeLeeuwenburg
    Apr 12, 2009
  4. davidani
    Replies:
    0
    Views:
    421
    davidani
    Jun 11, 2011
  5. david dani
    Replies:
    1
    Views:
    703
    Vinay Sajip
    Jun 12, 2011
Loading...

Share This Page