Skip to main content
added 14 characters in body
Source Link
Andy Dalton
  • 14.7k
  • 1
  • 28
  • 50

I have a program that creates four shared memory objects. The memory creation routine calls shm_unlinkshm_unlink() before attempting to create them, and the program calls another routine to delete them with shm_unlinkshm_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 fuserfuser showed that they were all owned by the same process, so I couldn't kill that.

I went to /dev/shm/dev/shm and did ls -lls -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 chownchown on the shm objects and change the owner?

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?

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?

Source Link
RTC222
  • 125
  • 6

Delete POSIX shared memory owned by different user

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?