#!/usr/bin/perl use strict; use warnings; use Fcntl qw/:DEFAULT :flock/; print "$$: Before open.\n"; sysopen (FILE, 'lockedfile', O_RDWR | O_CREAT) or die "$$: cannot open file: $!\n"; ### Einfacher, legt die Datei aber nicht an, wenn sie noch nicht existiert: # open FILE, '+<', 'lockedfile' or die "cannot open file (proc $$): $!\n"; print "$$: Before flock.\n"; flock FILE, LOCK_EX; print "$$: Writing to file.\n"; print FILE "Here is process $$.\n"; print "$$: Sleeping.\n"; sleep 30; print "$$: Closing file.\n"; close FILE; print "$$: Finished.\n";