Is semaphore an IPC mechanism?

前端 未结 4 852
逝去的感伤
逝去的感伤 2020-12-31 10:52

Is semaphore an IPC mechanism?

相关标签:
4条回答
  • 2020-12-31 11:19

    Yes, under many platforms semaphores can synchronize across processes. You would use "named" semaphores for this -- multiple processes access the object via a name, similar to filesystem objects.

    In POSIX, you can create named semaphores via sem_open(). For unamed semaphores, if the second parameter to sem_init() is nonzero, it can be interprocess, though I'm not sure exactly how an unnamed interprocess semaphore is supposed to work.

    Note that on some systems these functions may fail with ENOSYS if interprocess semaphores aren't supported (for example OpenBSD).

    In Windows, you can create named semaphores via CreateSemaphore() as @sergiom has mentioned.

    0 讨论(0)
  • 2020-12-31 11:19

    It depends on the operating system

    In Windows named semaphores can be accessed between processes using the CreateSemaphore() and OpenSemaphore() functions

    http://msdn.microsoft.com/en-us/library/ms682438%28VS.85%29.aspx

    0 讨论(0)
  • 2020-12-31 11:35

    POSIX semaphores can be unnamed or named. Unnamed semaphores are allocated in process memory and initialized. Unnamed semaphores might be usable by more than one process, depending on how the semaphore is allocated and initialized. [...]

    Would you like to know more?

    0 讨论(0)
  • 2020-12-31 11:40

    Actually Semaphore is a synchronisation tool but it is counted as an IPC bcoz it is accessed by more than 1 process

    0 讨论(0)
提交回复
热议问题