Reputation: 215
In Linux OS, named semaphores are created at /dev/shm/ location using sem_open API. I am creating named semaphore in Windows using CreateSemaphore. In which location are the named semaphores created in Windows?
Upvotes: 4
Views: 2631
Reputation: 5510
Windows named semaphores exist within the kernel's internal object namespace. This database has a filesystem-like hierarchical tree structure, but is not visible through regular filesystem functions. Use the Object Viewer tool from Sysinternals (now a subsidiary of Microsoft) to explore that space. Semaphores, unsurprisingly, have the object type Semaphore. Of other objects, the mutex is called Mutant (apparently, after David Cutler's reference to these as “mutant semaphores”, private communication). The EventPair object is not available though the Win32 API. All other synchronization primitives are self-recognizable there.
I do not think that the API used to access this data space from user space is fully documented. Windows DDK headers is are interesting read indeed.
Unnamed objects (those that are created with the NULL
passed as object name) are for single process use, and only optionally inherited by its child processes. These are not registered in the kernel object namespace.
Unlike POSIX semaphores, all Windows objects are automatically removed when the last handle to these is closed (as if sem_open
always called sem_unlink
), and all process handles are closed by the kernel's executive when the process terminates, be it a normal termination or an abort. I am mentioning that in case the motivation for your question was to verify that there are no semaphores left behind when all processes that use them die.
Upvotes: 4
Reputation: 31153
There is no filesystem or other location for semaphores in Windows, you only access them via CreateSemaphore
. Linux has virtual filesystems that provide access to several named kernel objects, but in Windows this is not the case and there rarely is any need for that.
More about kernel namespaces
Upvotes: 2