Get the name of the POSIX semaphore

Is there a way to get the name of the POSIX semaphore with the name ID (sem_t) in C ++?

Thanks to all and best wishes.

+4
source share
1 answer

Unfortunately not. There is no sem_name function in the POSIX semaphore (or whatever you call it). There is also no workaround for Linux, since it does not provide sem_name , and it does not save the name in sem_t , which is defined in <bits/semaphore.h> as

 typedef union { char __size[__SIZEOF_SEM_T]; long int __align; } sem_t; 

The files /proc/sys/kernel/sem and /proc/sysvipc/sem do not contain this information either.

So, your best option is to save the name yourself when executing sem_open , preferably in a wrapper class. See this answer for an example of a shell class.

+5
source

Source: https://habr.com/ru/post/1341421/


All Articles