信号量是IPC机制吗?
Is semaphore an IPC mechanism?
推荐答案是的,在许多平台上,信号量可以跨进程同步.为此,您将使用命名"信号灯-多个进程通过名称访问对象,类似于文件系统对象.
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.
在POSIX中,您可以通过sem_open()创建命名信号量.对于未修饰的信号量,如果sem_init()的第二个参数非零,则它可以是进程间的,尽管我不确定确切地说,未命名的进程间信号量应该如何工作.
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.
请注意,在某些系统上,如果不支持进程间信号量(例如OpenBSD),这些功能可能会失败并显示ENOSYS.
Note that on some systems these functions may fail with ENOSYS if interprocess semaphores aren't supported (for example OpenBSD).
在Windows中,您可以通过CreateSemaphore()创建已命名的信号灯,如@sergiom所述.
In Windows, you can create named semaphores via CreateSemaphore() as @sergiom has mentioned.
更多推荐
信号量是IPC机制吗?
发布评论