I have a program that creates four shared memory objects. The memory creation routine calls shm_unlink() before attempting to create them, and the program calls another routine to delete them with shm_unlink() at the end of the run.
Today I got "permission denied" on objects 2-4 (but not object 1) when attempting to re-create them. Linux fuser showed that they were all owned by the same process, so I couldn't kill that.
I went to /dev/shm and did ls -l, and found that 2-4 were owned by root, not by my sudo user. I rarely log on as root so I don't know how they became owned by root. To solve the problem, I logged on as root and deleted them manually.
My question is: is there a programmatic way to delete shared memory objects owned by a different user (e.g. root) without logging on as that user? Is there a way to call chown on the shm objects and change the owner?
sudo somecmdthen you are creating a new process, andsomecomdis run with uid=0 in that process, i.e. it is run as root. So did you start your program viasudo yourprogram?