信号量是一种IPC机制吗?

发布于 2024-08-21 06:11:00 字数 20 浏览 1 评论 0原文

信号量是一种IPC机制吗?

Is semaphore an IPC mechanism?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月苍老的讽刺 2024-08-28 06:11:00

是的,在许多平台下信号量可以跨进程同步。为此,您可以使用“命名”信号量——多个进程通过名称访问对象,类似于文件系统对象。

在 POSIX 中,您可以通过 sem_open() 创建命名信号量。对于未命名信号量,如果第二个参数为 sem_init() 是非零,它可以是进程间的,尽管我不确定未命名的进程间信号量应该如何工作。

请注意,在某些系统上,如果不支持进程间信号量(例如 OpenBSD),这些函数可能会因 ENOSYS 而失败。

在 Windows 中,您可以通过 CreateSemaphore( ) 正如@sergiom 提到的。

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.

你怎么敢 2024-08-28 06:11:00

这取决于操作系统。

在 Windows 中,可以使用 CreateSemaphore() 和 OpenSemaphore() 函数在进程之间访问命名信号量

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

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

烧了回忆取暖 2024-08-28 06:11:00

实际上Semaphore是一个同步工具,但它被算作一个IPC,因为它被超过1个进程访问

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

宛菡 2024-08-28 06:11:00

POSIX 信号量可以是未命名的或
命名。未命名信号量是
分配在进程内存中并且
已初始化。未命名的信号量可能
可被多个进程使用,
取决于信号量的情况
分配并初始化。 [...]

您想了解更多< /a>?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文