aboutsummaryrefslogtreecommitdiff
path: root/flock_mmap/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'flock_mmap/README.md')
-rw-r--r--flock_mmap/README.md50
1 files changed, 50 insertions, 0 deletions
diff --git a/flock_mmap/README.md b/flock_mmap/README.md
new file mode 100644
index 0000000..623fd5c
--- /dev/null
+++ b/flock_mmap/README.md
@@ -0,0 +1,50 @@
+# Mixing flock() and close() on Various Unices
+https://stackoverflow.com/questions/70045539/file-retains-lock-after-mmap-and-close
+
+This turned out to be a bigger problem than I thought. Well, too late to fix the
+kernel now.
+
+Added `fcntl()` as control.
+
+## INSTALL
+```sh
+mkdir flock_mmap
+cd flock_mmap
+
+wget \
+ https://github.com/dxdxdt/gists/raw/master/flock_mmap/tests.sh \
+ https://github.com/dxdxdt/gists/raw/master/flock_mmap/Makefile \
+ https://github.com/dxdxdt/gists/raw/master/flock_mmap/flock_mmap.c \
+ https://github.com/dxdxdt/gists/raw/master/flock_mmap/README.md
+
+chmod 755 tests.sh
+```
+
+## Run it
+```sh
+make 2> /dev/null
+```
+
+### Result A
+- Linux
+
+```
+./tests.sh
+[TEST]fcntl(fd, F_SETLK, ...) and close() unlocks the file: YES
+[TEST]fcntl(fd, F_SETLK, ...) and holding unlocks the file: NO
+[TEST]flock() and close() unlocks the file*: NO
+[TEST]flock() and holding unlocks the file : NO
+```
+
+### Result B
+- FreeBSD
+- OpenBSD
+- mac
+
+```
+./tests.sh
+[TEST]fcntl(fd, F_SETLK, ...) and close() unlocks the file: YES
+[TEST]fcntl(fd, F_SETLK, ...) and holding unlocks the file: NO
+[TEST]flock() and close() unlocks the file*: YES
+[TEST]flock() and holding unlocks the file : NO
+```