in reply to Re: Filenames based on timestamp
in thread Filenames based on timestamp

This is prone to race conditions when several processes are involved. Between the -e test and the actual file creation, a file of the name in question may have been created by another process.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Re: Filenames based on timestamp
by robobunny (Friar) on Jun 27, 2002 at 17:21 UTC
    that's true. you could work around that by also included a PID in the filename.
    while(-e "$time_$$_$counter") { $counter++; } open(F, ">$time_$$_$counter");
    of course, then the filenames won't necessarily be in ascending order chronologically.
      what about multiple threads :-)

      page 572-574 of camel3 suggests something along the lines of...
      $fn = "filename_20020723141223_"; my $c = 1; do { $fn .= "$c"; $c++; } until sysopen(FH, $fn, O_RDWR | O_CREAT | O_EXCL, 0600); # now do I/O using $fh handle...