Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between System V and Posix semaphores

What are the trade-offs between using a System V and a Posix semaphore?

like image 481
corto Avatar asked Dec 15 '08 13:12

corto


People also ask

What is System V semaphore?

Semaphores enable processes to query or alter status information. They are often used to monitor and control the availability of system resources such as shared memory segments.

What is IPC V?

System V IPC is the name given to three interprocess communication mechanisms that are widely available on UNIX systems: message queues, semaphore, and shared memory. Message queues System V message queues allow data to be exchanged in units called messages.

What is System V shared memory?

A shared memory segment is described by a control structure with a unique ID that points to an area of physical memory. The identifier of the segment is called the shmid. The structure definition for the shared memory segment control structure can be found in sys/shm. h .


1 Answers

From O'Reilly:

  • One marked difference between the System V and POSIX semaphore implementations is that in System V you can control how much the semaphore count can be increased or decreased; whereas in POSIX, the semaphore count is increased and decreased by 1.
  • POSIX semaphores do not allow manipulation of semaphore permissions, whereas System V semaphores allow you to change the permissions of semaphores to a subset of the original permission.
  • Initialization and creation of semaphores is atomic (from the user's perspective) in POSIX semaphores.
  • From a usage perspective, System V semaphores are clumsy, while POSIX semaphores are straight-forward
  • The scalability of POSIX semaphores (using unnamed semaphores) is much higher than System V semaphores. In a user/client scenario, where each user creates her own instances of a server, it would be better to use POSIX semaphores.
  • System V semaphores, when creating a semaphore object, creates an array of semaphores whereas POSIX semaphores create just one. Because of this feature, semaphore creation (memory footprint-wise) is costlier in System V semaphores when compared to POSIX semaphores.
  • It has been said that POSIX semaphore performance is better than System V-based semaphores.
  • POSIX semaphores provide a mechanism for process-wide semaphores rather than system-wide semaphores. So, if a developer forgets to close the semaphore, on process exit the semaphore is cleaned up. In simple terms, POSIX semaphores provide a mechanism for non-persistent semaphores.
like image 59
ezkl Avatar answered Oct 10 '22 02:10

ezkl