Obtain POSIX semaphore's name Obtain POSIX semaphore's name unix unix

Obtain POSIX semaphore's name


Unfortunately, no. There is no sem_name (or whatever you'd call it) function in the POSIX semaphore spec. There is also no Linux-specific workaround, since it provides no sem_name either and it does not store the name in the 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 don't seem to contain this information either.

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