On mac os, how to remove a POSIX named semaphore in IPC with command line?

Viewed 287

I create some POSIX named semaphores in my program with sem_open(),

sem_t semfoo = sem_open("/semfoo", O_CREAT | O_EXCL, S_IREAD | S_IWRITE, 10);

And remove it with sem_unlink()

sem_unlink("/semfoo");

Sometimes when the program exit improperly, the sem_unlink() wasn't executed. So the semaphores still exist in shared memory. Then my next run will crash because of it. I have to create another .c file to unlink it manually.

I know there is /dev/shm in linux to check the semaphore stay in shared memory, but not for mac os. I also tried ipcs -l, but nothing listed,

T     ID     KEY        MODE       OWNER    GROUP
Message Queues:

T     ID     KEY        MODE       OWNER    GROUP
Shared Memory:

T     ID     KEY        MODE       OWNER    GROUP
Semaphores:

So is there some command line tools that I can use to check and remove the semaphores in shared memory on mac os, so that I don't need to create a new .c file to do so. Thanks.

0 Answers
Related