Re: question about forked processes writing to the same file




Gunnar Hjalmarsson wrote:
> it_says_BALLS_on_your forehead wrote:
> > is this dangerous? for instance, is there ever a danger of race
> > conditions/locking/etc if i have:
> >
> > use strict; use warnings;
> > use Parallel::ForkManager;
> >
> > my $pm = Parallel::ForkManager->new(10);
> >
> > # assume @files contains 100 files that will be processed,
> > # and processing time could range from subseconds to hours
> >
> > my $out = 'results.txt';
> > for my $file (@files) {
> > $pm->start and next;
> >
> > # some code to process file
> > # blah blah blah
> >
> > open( my $fh_out, '>>', $out ) or die "can't open $out: $!\n";
> > print $fh_out "$file\n";
> > close $fh_out;
> >
> > $pm->finish;
> > }
> > $pm->wait_all_children;
>
> As long as you don't care about the order in which the output from
> respective file is appended to $out, I can't see what the problem would be.
>

order is unimportant at this juncture. i was concerned if one process
would interrupt another that was writing, so that either both failed,
or a single entry became a garbled hybrid of two entries...something
along those lines. these, or other cases that may interfere with
writing one entry per line to $out, are what cause me apprehension.

.



Relevant Pages

  • Re: question about forked processes writing to the same file
    ... # and processing time could range from subseconds to hours ... would interrupt another that was writing, so that either both failed, or a single entry became a garbled hybrid of two entries...something along those lines. ...
    (comp.lang.perl.misc)
  • Re: Extreme images prosecutions start - will you be next?
    ... If you're writing about a serial killer, for example, it might be valid in terms of the killer's pathology. ... The idea was to cause shock and outrage, which it did, but the end result was that a complaint to my educational establishment resulted in the poem being sent to the Metropolitan Police and my educational establishment insisting that I attend an appointment with a forensic psychiatrist in order to evaluate whether I was a danger to society. ...
    (uk.legal)
  • Re: Harry Potter books sold in Israel
    ... maturing audience with maturing characters. ... Here's how I look at it: the writing, and the story, grew with the ... and even dangerous situations aren't the same sort of danger that adults ...
    (soc.culture.jewish.moderated)
  • Re: question about forked processes writing to the same file
    ... is there ever a danger of race ... >> # and processing time could range from subseconds to hours ... >> # blah blah blah ... On Linux this is safe, provided the string $file is not more than a few ...
    (comp.lang.perl.misc)
  • Re: More Bad News from Iran
    ... into the street and beaten by an angry mob for writing.. ... :> own supposedly sovreign border. ... Is there danger there? ... Get out of the Army Bryan. ...
    (rec.sport.football.college)