In System V shared memory (shmget()), it is possible to find out how many attached users there are for a segment by using shmctl(... IPC_STAT ...) and reading the field shm_nattch of the resulting data structure.
With POSIX shared memory (shm_open()), is there any way to do something similar, or at least find out whether anyone is attached?
There is at least one way, somewhat cumbersome and probably not quite portable. You can scan
/procfilesystem looking for processes that have this SHM object opened. Usereadlinkon"/proc/<self-PID>/fd/<shm-FD>"to get the object path, and then scan “/proc/[0-9]+/fd/*symlinks, comparing file names they point to or, better yet, device and inode numbers as returned bystat. Or you can simply delegate this task tofuserutility and parse its output.