1File::Flock(3) User Contributed Perl Documentation File::Flock(3)
2
3
4
6 File::Flock - file locking with flock
7
9 use File::Flock;
10
11 lock($filename);
12
13 lock($filename, 'shared');
14
15 lock($filename, undef, 'nonblocking');
16
17 lock($filename, 'shared', 'nonblocking');
18
19 unlock($filename);
20
21 lock_rename($oldfilename, $newfilename)
22
23 my $lock = new File::Flock '/somefile';
24
25 $lock->unlock();
26
27 $lock->lock_rename('/new/file');
28
29 forget_locks();
30
32 Lock files using the flock() call. If the file to be locked does not
33 exist, then the file is created. If the file was created then it will
34 be removed when it is unlocked assuming it's still an empty file.
35
36 Locks can be created by new'ing a File::Flock object. Such locks are
37 automatically removed when the object goes out of scope. The unlock()
38 method may also be used.
39
40 lock_rename() is used to tell File::Flock when a file has been renamed
41 (and thus the internal locking data that is stored based on the
42 filename should be moved to a new name). unlock() the new name rather
43 than the original name.
44
45 Locks are released on process exit when the process that created the
46 lock exits. Subprocesses that exit do not remove locks. Use
47 forget_locks() or POSIX::_exit() to prevent unlocking on process exit.
48
50 See File::Flock::Subprocess for a variant that uses a subprocess to
51 hold the locks so that the locks survive when the parent process forks.
52 See File::Flock::Forking for a way to automatically choose between
53 File::Flock and File::Flock::Subprocess.
54
56 Copyright (C) 1996-2012 David Muir Sharnoff <cpan@dave.sharnoff.org>
57 Copyright (C) 2013 Google, Inc. This module may be used/copied/etc on
58 the same terms as Perl itself.
59
61 File::Flock is packaged for Fedora by Emmanuel Seyman
62 <emmanuel.seyman@club-internet.fr>.
63
64
65
66perl v5.38.0 2023-07-20 File::Flock(3)