I have a process that (by design) fails to start if its shared memory created with shm_open(2) already exists. If the process crashes or is kipped with pkill(1), the process will not start until FreeBSD is rebooted. I'm looking to create a "clean" sh script to detect if the shared memory exists and close/remove it if needed.
Previously (on another operating system), I just viewed and cleared the shared memory files directly; however, as per https://forums.freebsd.org/threads/freebsd-8-x-changes-in-shm_open.16850/, shm_open(2) does not actually create files in the given path for FreeBSD 12.3.
Other forum posts have said to use ipcs(1) to see a list and ipcrm(1) to clean; however ipcs(1) shows nothing under shared memory. I'm guessing that is for a mechanism different from shm_open(2).
Using fstat(1), I can see that share memory exists (although the path given is not actually visible in the file system).
Is there any way in FreeBSD to clean shared memory (without rebooting) with a path matching a given pattern?
Previously (on another operating system), I just viewed and cleared the shared memory files directly; however, as per https://forums.freebsd.org/threads/freebsd-8-x-changes-in-shm_open.16850/, shm_open(2) does not actually create files in the given path for FreeBSD 12.3.
Other forum posts have said to use ipcs(1) to see a list and ipcrm(1) to clean; however ipcs(1) shows nothing under shared memory. I'm guessing that is for a mechanism different from shm_open(2).
Using fstat(1), I can see that share memory exists (although the path given is not actually visible in the file system).
Code:
my_user my_process 2542 25 /tmp/my-shm.a.file1 -rw-r--r-- 544 rw
my_user my_process 2542 26 /tmp/my-shm.a.file2 -rw-r--r-- 544 rw
my_user my_process 2542 27 /tmp/my-shm.a.file3 -rw-r--r-- 560 rw
my_user my_process 2542 28 /tmp/my-shm.b.file4 -rw-r--r-- 560 rw
my_user my_process 2542 29 /tmp/my-shm.b.file5 -rw-r--r-- 544 rw
my_user my_process 2542 30 /tmp/my-shm.b.file6 -rw-r--r-- 544 rw
Is there any way in FreeBSD to clean shared memory (without rebooting) with a path matching a given pattern?