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
/* | |
# flock in C | |
## Motivation | |
Try and search for "Flock in C" on YouTube. You won't find this stuff. | |
## Explanation | |
This tiny project is to show how to use a file to share data between 2 processes. For simplicity, a producer and a consumer are created within the same executable. | |
The producer uses `flock` with the "exclusive" flag. That is because the producer wants nobody else to access the file while it is being written. Also, the producer prefers to wait for readers to complete reading. Hence, the producer blocks until the readings are in progress. |