I am working on a watchdog for a multiprocess system on a linux-based OS that will simply check if a segment of shared memory has been written within a configurable timeout. Ideally, the watchdog will not have to know the layout or contents of the shared memory segment, only the segment id or virtual filepath.
I have tried regularly executing stat() on the virtual file, but it appears that st_mtime
is not updated when the memory-mapped segment is written to, only when the file is created, see here for more information.
The best I have come up with involves executing a hash function on the virtual memory file of the segment. The hash changes regularly with each write to the segment. However, this is somewhat cumbersome and expensive. While I could use some internal signaling from the main process, I'd prefer to keep the watchdog focused on whether or not new data has been added to the shared memory segment. Is there a better way to determine the last modified time of a shared memory segment? Or, that it has been modified within the last N seconds?
I primarily use python but C++ would also be accepted if some required syscalls cannot be made from python.