Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • Thank you for your excellent answer. As shown below, public static int lockf (int fd, LockfCommand cmd, long len) takes an integer file descriptor rather than a file pointer. How do I handle that? Could I convert a linux file pointer to an linux file descriptor? Commented Apr 18, 2016 at 12:32
  • Do we have to mmap the empty file for mutual exclusion? Thank you. Commented Apr 18, 2016 at 15:16
  • The simplest way is to use the open method in the same class to open a file and return its file descriptor. And you don't need to map the lock file, on the data file. Commented Apr 18, 2016 at 15:36
  • What is the purpose of creating a file in transient storage area of and then opening that in both processes, and use mmap to map the file into both processes' memory space. as well as sharing the data by reading & writing into the mapped area? We understand the purpose of your mutual exclusion. Thank you. Commented Apr 18, 2016 at 19:05
  • The transient file exists to create a globally-accessible name that any process can refer to. It also defines the size of the memory block that can be shared between the processes. By using mmap on the same file, any processes can gain access to the same shared data. Using the /run filesystem prevents the overhead of the data ever being flushed to disk, as it is (typically) a memory-only filesystem ("tmpfs"). Commented Apr 18, 2016 at 19:33