Created
April 22, 2014 07:32
-
-
Save kazuho/11168660 to your computer and use it in GitHub Desktop.
tempfile, UNLINK, and flock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| my $fn = do { | |
| # some BSD variants (notably OS X) flocks the file handle when calling tempfile() | |
| my ($fh, $fn) = tempfile(UNLINK => 1); | |
| $fn | |
| # setting UNLINK => 1 keeps a hidden reference to the file handle, and thus the file | |
| # is not automatically closed when exitting this block | |
| }; | |
| open my $fh, "<", $fn | |
| or die $!; | |
| # flock blocks forever since the file is already locked | |
| flock($fh, LOCK_EX) | |
| or die $!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment