doc:appunti:prog:perl_flock
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| doc:appunti:prog:perl_flock [2011/02/26 14:44] – created niccolo | doc:appunti:prog:perl_flock [2011/02/26 14:56] (current) – niccolo | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| <code perl> | <code perl> | ||
| + | # | ||
| + | |||
| use Fcntl ': | use Fcntl ': | ||
| Line 9: | Line 11: | ||
| # Try to lock the file, waiting 5 seconds max. | # Try to lock the file, waiting 5 seconds max. | ||
| + | $i = 0; | ||
| while (! flock(FILE, LOCK_EX | LOCK_NB)) { | while (! flock(FILE, LOCK_EX | LOCK_NB)) { | ||
| if (++$i > 5) { | if (++$i > 5) { | ||
| Line 18: | Line 21: | ||
| # Now the file open and locked. | # Now the file open and locked. | ||
| + | print "File is locked!\n"; | ||
| + | sleep(20); | ||
| # Unlock and close the file. | # Unlock and close the file. | ||
doc/appunti/prog/perl_flock.1298727875.txt.gz · Last modified: by niccolo
