As the name suggests, the semaphore does not have a name in the Linux File system. These semaphores are also called as memory-based semaphores. since, the semaphore does not have a name associated with it in the Linux File system, the semaphore needs to be placed in a shared memory region that different processes or threads share.
the “sem_init” function initializes the semaphore. It also informs whether the semaphore will be shared between processes or threads of a single process.
- pshared – if value is 0 – semaphore is shared between threads of same parent process. If non-zero – semaphore is shared between processes. The semaphore in such a scenario needs to be created in a shared memory region.
- value – initial value of the semaphore
The sem_post and sem_wait functions can be used to release and obtain a semaphore.
Pingback: Named Semaphore in Linux user space | Hitch Hiker's Guide to Learning