Is semaphore an IPC mechanism?

戏子无情 提交于 2019-11-30 13:52:46

问题


Is semaphore an IPC mechanism?


回答1:


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.




回答2:


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




回答3:


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




回答4:


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?



来源:https://stackoverflow.com/questions/2243205/is-semaphore-an-ipc-mechanism

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!