Skip to content

Misc. POSIX shm and sem Incompatibilities Between Linux, Solaris and macOS

Andreas Kersting edited this page Dec 11, 2020 · 3 revisions

General

  • Linux allows names of up to 255 characters, macOS just 31

POSIX Shared Memory

  • on Linux and Solaris we need to link with -lrt, but not so on macOS
  • fstat on Linux and Solaris reports the actual size of the object, while on macOS it reports the size in multiples of 4KiB (page size, I guess)
  • on macOS, shm_open with O_TRUNC (and O_CREAT | O_RDWR) fails with "Invalid argument" (works on Linux and Solaris)
  • on macOS, privately mapping a shared memory object fails with "Invalid argument" (works on Linux and Solaris)
  • on macOS, "ftruncate only works once on the initial creation of the segment" (cf. https://stackoverflow.com/a/25510361)

POSIX Semaphores

  • recreating an already existing semaphore on Linux returns the identical sem_t *, which can be passed to sem_close twice afterwards; on macOS a different sem_t * is returned