0

I have two programs in Linux (one in C++, one in python) which are communicating via interprocess-communications, using shared memory.

What I would need now is a shell-script I can invoke after both have finished, which deletes ALL shared memory segments for my linux user which are not used anymore (so have status 'dest' in the list I get from command 'ipcs -m').

So I do not want to keep of course shared memory segments which are in use by another user, and I want to keep shared memory segments which are currently used (e.g. by a Pytorch training running in parallel).

How can I achieve that on the command-line ? There are a lot of answers at Delete all SYSTEM V shared memory and semaphores on UNIX-like systems, but I think the do not check the status of the shared memory segment, and possibly also not to which user it belongs.

user2454869
  • 105
  • 1
  • 11
  • `possibly also not to which user it belongs.` There's `grep $ME` for that. Where `ME=whoami`. `the status of the shared memory segment` What is there to check? – KamilCuk Nov 15 '21 at 10:03
  • The status of the shared memory indicates (I think so) whether it is still used or not. And I want to delete only the shared memory segments that are not used anymore. In windows, a shared memory segment is automatically deleted when no process uses it anymore. I want something similar also in linux. – user2454869 Nov 15 '21 at 10:30
  • Are you allowed to use [proc(5)](https://man7.org/linux/man-pages/man5/proc.5.html) and `/proc/self/maps` from inside one of the programs? Are you permitted to consider using [shm_overview(7)](https://man7.org/linux/man-pages/man7/shm_overview.7.html) and `/dev/shm/` ? Did you consider using [pipe(7)](https://man7.org/linux/man-pages/man7/pipe.7.html) ? – Basile Starynkevitch Nov 15 '21 at 12:16
  • Well, I would prefer to do this via a shell script, and not from within the C++/python programs – user2454869 Nov 15 '21 at 16:40

0 Answers0