What this is about:
flock performs several open / lock operations on files. It is an application
that demonstrates "conflicting" locks and access between two programs.
the demonstation works by opening two windows and running "flock first" in the
first window, and "flock second" in the second window.
It looks (runs) like this:
File open|Instance activity
by inst #|
data flag|first second
---------+---------------------------------------------------------------------
- Start
- Delete the flag.file
1 - Open delete.me with an
1 exclusive lock
1 - Write data to delete.me
1 - Wait for second instance
1 by trying to open flag.file
1 - Start
1 2 - Create flag.file
1 2 - Write our pid to flag.file
1 2 - Close flag.file
1 - Block on open attempt of delete.me
1 1 - Succeed opening flag.file
1 1 - Read pid of second instance
1 1 - Echo pid to stdout
1 1 - Remove flag.file
1 - Hold delete.me open for 10
1 seconds.
1 - Close delete.me
2 - Sleep - Succeed opening delete.me with a
2 for shared lock on the file.
2 a - Read characters from the file.
2 second - Upgrade the lock on delete.me
2 - Block on open of delete.me to exclusive lock.
2 with shared lock - Write a character
2 - Hold delete.me open for 10 seconds
1+2 - Succed on open of delete.me - Downgrade delete.me lock to shared
1+2 - Close delete.me - Hold delete.me open for 10 seconds
2 - Close delete me.