user17569516
user17569516

Reputation:

What is a semaphore value on process exit?

If a named semaphore's value is increased by post operation from a process would it retain this value even if the process exits abruptly? Will the restarted/re-executed process be able to observe this increased value?

Upvotes: 0

Views: 378

Answers (1)

patoglu
patoglu

Reputation: 411

Named semaphores are stored in persistent storage unless you don't call sem_unlink. According to the man page:

   On Linux, named semaphores are created in a virtual filesystem,
   normally mounted under /dev/shm, with names of the form
   sem.somename.

and according to the man page again, this should answer your question (simply yes.):

The sem_open(3) function creates a new named semaphore or opens an existing named semaphore. After the semaphore has been opened, it can be operated on using sem_post(3) and sem_wait(3). When a process has finished using the semaphore, it can use sem_close(3) to close the semaphore. When all processes have finished using the semaphore, it can be removed from the system using sem_unlink(3).

Upvotes: 2

Related Questions