centos - In POSIX named semaphores, sem_unlink() removes the name of the semaphore -


the semaphore name removed if 'there no open references semaphore'(*)

  • 1) these 'references'?
  • 2) can these references queried identify involved processes?

the same paragraph continues elaborate 'if there no open references semaphore, destroyed. otherwise, destruction deferred until last open reference closed'. means me os continue query these references until able destroy semaphore. there more these 'references' value of semaphore?

(*)w.r. stevens, s.a. rago 'advanced programming in unix environment', 3rd edition, pg. 581.

"what these 'references'?"

a named semaphore identified name of form /somename; is, null-terminated string of name_max-4 (i.e., 251) characters consisting of initial slash, followed 1 or more characters, none of slashes. 2 processes can operate on same named semaphore passing same name sem_open(3).

thi means process creates (o_creat flag passed sem_open(3)) named semaphore (in form of /somename) allow process may operate on named semaphore if has enough privileges (based on process uid / gid creating semaphore mode passed sem_open(3)).

this simple way (analogous 2 processes opening same file) identify [and operate over] same semaphore on 2 or more different processes.

"can these references queried identify involved processes?"

no (at least, in posix way).

"this means me os continue query these references until able destroy semaphore."

although implementation specific, there's no need os keep querying semaphore in order determine if can unlinked. see simple reference counter: if sem_unlink() called process#3, process#2 , process#1 still using semaphore, reference counter 2 @ point. need evaluate reference counter value @ every sem_close() or sem_unlink() call determine when reaches 0, unlinking named semaphore.


Comments